shiki_flutter_native_engine library
A ShikiHighlighterEngine backed by the real Oniguruma C library (via the
standalone oniguruma_native package): dart:ffi on IO and WebAssembly on
web, tokenizing with Oniguruma instead of shiki_flutter's pure-Dart engine.
Enable it once in main(). On web the wasm module loads asynchronously, so
await loadWasm() before the first highlight; it is a no-op on IO, so the
same startup code is portable:
import 'package:shiki_flutter/shiki_flutter.dart';
import 'package:shiki_flutter_native_engine/shiki_flutter_native_engine.dart';
Future<void> main() async {
await loadWasm(); // no-op on IO; loads the embedded wasm on web
ShikiHighlighter.config = ShikiHighlighter.config.copyWith(
ioEngine: const ShikiHighlighterNativeEngine());
runApp(const MyApp());
}
A per-highlighter override is also possible:
createHighlighter(engine: ShikiHighlighterNativeEngine()).
At parity with the pure-Dart engines: oniguruma_native drives Oniguruma in
UTF-8 (mapping match offsets back to UTF-16 code units for Dart String
indices), so 2-digit \xHH byte escapes (e.g. CSS's [^\x00-\x7F]) compile
correctly. test/parity_test.dart asserts byte-identical output against the
golden-tested pure-Dart engine across the sampled languages (json, javascript,
css, python, html) and themes.
Classes
- ShikiHighlighterNativeEngine
-
A
ShikiHighlighterEnginethat runs the real Oniguruma C engine throughoniguruma_native:dart:ffion IO and WebAssembly on web.