flutter_syntax_highlight 0.2.0
flutter_syntax_highlight: ^0.2.0 copied to clipboard
Dart-only syntax highlighting in two layers: a pure-Dart tokenizer underneath and a thin widget on top. The tokens rejoin into the exact input, byte for byte.
Changelog #
0.2.0 #
The palette derived from your ColorScheme now borrows your app's accent, in
two places, diluted. Nothing else changed; the tokenizer is untouched.
string(andescape, which follows its literal) is pulled fromonSurfaceVarianttowardstertiary;function, which had no style at all, is pulled fromonSurfacetowardsprimary.numberandpunctuationstay where they were, so the literals gain a distinction between them.- It still introduces no hue of its own — every colour is a neutral role from your scheme or a neutral role mixed with one of your scheme's accents, and a monochrome scheme still yields a monochrome palette.
- How far to pull was measured over the whole hue circle in both brightnesses,
against two scales this palette already contained. See
docs/adr/0003-the-derived-default-borrows-the-app-s-accent-diluted.md. - The example gained a seed picker, so the derivation is visible rather than merely claimed.
Named presets are unchanged. If you pass one, or your own SyntaxPalette,
nothing about this release affects you.
0.1.0 #
First release.
Tokenizer #
tokenizeDart(String source)returns aList<DartToken>whose texts concatenate back to the input, byte for byte. Tokens are cut at recorded offsets and never rebuilt, so CRLF and letter case survive unchanged.- The file imports nothing — not Flutter, not
dart:*— and a test fails if that ever stops being true. - Eight kinds, every one decidable by scanning characters left to right:
plain,comment,keyword,string,number,punctuation,escape,function. Distinctions that need a parser are deliberately absent; the reasoning is indocs/adr/0001-token-kinds-are-lexical-only.md. - The inside of
${...}is scanned recursively with the same rules as the outside, so a string nested in an interpolation comes back out as a string. Nested block comments, raw strings, triple-quoted strings, and unterminated strings and interpolations are each handled, the last two by stopping at the end of the line.
Widget #
SyntaxText(source, {palette, copyable, scrollable, fontFamily, fontFamilyFallback, fontSize, height, padding, copyTooltip, copiedTooltip})draws selectable, copyable code. It takes a string, not an asset key, so it has no loading state.- Horizontal scrolling is always owned by the widget — code does not wrap.
scrollablegoverns the vertical axis only. SyntaxPaletteholds one optionalTextStyleper kind plus an optionalbackground.SyntaxPalette.fromColorSchemederives the default from the consumer'sColorSchemewithout introducing a hue of its own, and paints no background, so it is right in light and dark with nothing to configure.- Ten named presets —
solarizedDark,solarizedLight,oneDark,oneLight,monokai,gruvboxDark,gruvboxLight,tokyoNight,tokyoNightLight,cobalt2— each an excerpt of an MIT-licensed upstream theme, carrying the background its colours were chosen against. Provenance, pinned commit by pinned commit, is inNOTICES.
