syntaxHighlighting function
Wrap a highlighter in an editor extension that uses it to apply syntax highlighting to the editor content.
When multiple (non-fallback) styles are provided, the styling applied is the union of the classes they emit.
Example
EditorState.create(
extensions: [
someLanguage(),
syntaxHighlighting(myHighlightStyle),
],
);
Implementation
Extension syntaxHighlighting(
Highlighter highlighter, {
/// When enabled, this marks the highlighter as a fallback, which
/// only takes effect if no other highlighters are registered.
bool fallback = false,
}) {
final ext = <Extension>[
// Install the tree highlighter plugin and its decoration provider
treeHighlighter.extension,
];
String? themeType;
if (highlighter is HighlightStyle) {
themeType = highlighter.themeType;
}
if (fallback) {
ext.add(_fallbackHighlighter.of(highlighter));
} else if (themeType != null) {
// For theme-specific highlighters, we'd need computeN with darkTheme facet
// For now, just add it directly
ext.add(_highlighterFacet.of(highlighter));
} else {
ext.add(_highlighterFacet.of(highlighter));
}
return ExtensionList(ext);
}