flutter_syntax_highlight 0.2.0 copy "flutter_syntax_highlight: ^0.2.0" to clipboard
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 (and escape, which follows its literal) is pulled from onSurfaceVariant towards tertiary; function, which had no style at all, is pulled from onSurface towards primary. number and punctuation stay 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 a List<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 in docs/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. scrollable governs the vertical axis only.
  • SyntaxPalette holds one optional TextStyle per kind plus an optional background. SyntaxPalette.fromColorScheme derives the default from the consumer's ColorScheme without 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 in NOTICES.
0
likes
160
points
162
downloads
screenshot

Documentation

API reference

Publisher

verified publisherkihyun1998.com

Weekly Downloads

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.

Repository (GitHub)
View/report issues

Topics

#syntax-highlighting #tokenizer #code #text #widget

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_syntax_highlight