MarkdownHighlighter class final

A SyntaxHighlighter driven by Grammars.

The caller supplies the exact set of languages to support, so only the grammars named here are retained; every other language is dropped by tree-shaking.

MarkdownHighlighter(
  languages: {'dart': HighlightDart.grammar, 'json': HighlightJson.grammar},
  theme: HighlightThemes.githubDark,
)
Implemented types

Constructors

MarkdownHighlighter({required Map<String, Grammar> languages, required CodeHighlightTheme theme})
Creates a highlighter for the given languages, styled by theme.

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 CodeHighlightTheme
The theme used to color tokens.
final

Methods

backgroundFor(String? language) Color?
The background color to use for language's code block, or null to keep the ambient surface color.
override
baseStyleFor(String? language, TextStyle fallback) TextStyle
The base style for language's code, derived from fallback (the code block's monospace style). Used to apply the theme's default foreground so untokenized code stays legible on the theme background.
override
highlight(String code, String? language, TextStyle baseStyle) List<InlineSpan>
Returns the spans for code, tagged for language. Implementations must preserve text exactly: the concatenation of the returned spans' text must equal code, so selection and copy stay aligned. baseStyle is the code block's base (monospace) style, already applied to the enclosing span.
override
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