shiki_flutter_engine_interface 1.0.0 copy "shiki_flutter_engine_interface: ^1.0.0" to clipboard
shiki_flutter_engine_interface: ^1.0.0 copied to clipboard

The regex-engine seam shared by shiki_flutter and its engine backends: the ShikiHighlighterEngine factory plus the OnigScanner/OnigString contract the TextMate tokenizer runs on.

shiki_flutter

shiki_flutter_engine_interface #

The regex-engine seam shared by shiki_flutter and its engine backends. It is a tiny, dependency-free package holding only the contract the TextMate tokenizer runs on:

  • ShikiHighlighterEngine: the factory that builds scanners and strings.
  • OnigScanner: finds the earliest match among a set of patterns on a line.
  • OnigString, OnigMatch, OnigCaptureIndex, kUnmatchedOffset: the value types passed across that seam.

It mirrors vscode-textmate's IOnigLib / onigLib.ts and Shiki's JavaScript scanner.ts.

Installation #

dependencies:
  shiki_flutter_engine_interface: ^1.0.0

Most apps never add this directly: it comes in transitively through shiki_flutter and whichever engine package you depend on (shiki_flutter_dart_engine, shiki_flutter_native_engine). Depend on it directly only if you're implementing your own ShikiHighlighterEngine.

Why it exists #

shiki_flutter's regex engine is pluggable. Extracting the contract into its own package means every implementation depends on the same types and can be swapped in interchangeably:

Package Engine Backend
shiki_flutter ShikiHighlighterEmbeddedEngine (web default) shiki_flutter's own pure-Dart engine
shiki_flutter_dart_engine ShikiHighlighterDartEngine (native/VM default) oniguruma_dart port (pure Dart, web included)
shiki_flutter_native_engine ShikiHighlighterNativeEngine native Oniguruma C via dart:ffi (IO only)

Because this package pulls in nothing (not even Flutter), a backend can implement the seam without depending on all of shiki_flutter.

Usage #

Implementing an engine #

import 'package:shiki_flutter_engine_interface/shiki_flutter_engine_interface.dart';

class MyEngine implements ShikiHighlighterEngine {
  const MyEngine();

  // A stable literal (not derived from runtimeType, which minifies on web).
  @override
  String get id => 'my-engine';

  @override
  OnigScanner createScanner(List<String> sources) => MyScanner(sources);

  @override
  OnigString createString(String str) => OnigString(str);
}

Then point the highlighter at it, e.g. on IO: ShikiHighlighter.config = ShikiHighlighter.config.copyWith(ioEngine: const MyEngine());.

0
likes
160
points
112
downloads

Documentation

API reference

Publisher

verified publisherbirju.dev

Weekly Downloads

The regex-engine seam shared by shiki_flutter and its engine backends: the ShikiHighlighterEngine factory plus the OnigScanner/OnigString contract the TextMate tokenizer runs on.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on shiki_flutter_engine_interface