highlight library
Tree-shakeable syntax highlighting for fenced code blocks.
Import this entrypoint for the engine and the MarkdownHighlighter, then
one small library per language you use (e.g. highlight/dart.dart).
Languages you never import are dropped by the compiler.
import 'package:flutter_md/highlight.dart';
import 'package:flutter_md/highlight/dart.dart';
import 'package:flutter_md/highlight/themes.dart';
final theme = MarkdownThemeData(
textStyle: const TextStyle(),
highlighter: MarkdownHighlighter(
languages: {'dart': HighlightDart.grammar},
theme: HighlightThemes.githubDark,
),
);
Classes
- CodeHighlightTheme
- A theme that maps token types to text styles for code highlighting.
- Grammar
- A syntax grammar: an ordered list of GrammarToken rules applied to source text to produce styled spans.
- GrammarToken
- One rule of a Grammar: a pattern whose matches are tagged with type (and optionally re-tagged via alias), with optional nested highlighting via inside.
- MarkdownHighlighter
- A SyntaxHighlighter driven by Grammars.
- SyntaxHighlighter
- Turns the text of a fenced code block into styled InlineSpans.
Functions
-
compileHighlightPattern(
String source, {bool caseSensitive = true, bool multiLine = false, bool dotAll = false, bool unicode = false}) → RegExp - Compiles a highlighting pattern. If the source uses a regex feature Dart's engine rejects, returns a never-matching pattern so a single bad rule disables itself instead of breaking the whole language.