SyntaxHighlighter class
Syntax highlighter that converts code to ANSI-styled terminal output.
Uses the highlight.dart package for parsing and artisanal's Style system for rendering.
final highlighter = SyntaxHighlighter(theme: ChromaTheme.dark);
final highlighted = highlighter.highlight(
'void main() { print("Hello"); }',
language: 'dart',
);
print(highlighted);
Constructors
- SyntaxHighlighter({ChromaTheme? theme})
- Creates a syntax highlighter with the given theme.
- SyntaxHighlighter.adaptive({AdaptiveChromaTheme? adaptiveTheme, bool hasDarkBackground = true})
-
Creates a syntax highlighter that adapts to terminal background.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- theme → ChromaTheme
-
The color theme to use for highlighting.
final
Methods
-
highlightCode(
String code, {String? language}) → String - Highlights code and returns ANSI-styled output.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited