Skip to main content

syntax_core 0.0.1 copy "syntax_core: ^0.0.1" to clipboard
syntax_core: ^0.0.1 copied to clipboard

TextMate-grammar syntax highlighting in pure Dart. Tokenizes code with VS Code grammars and themes and renders tokens, diffs, HTML, or ANSI. No Flutter required.

example/main.dart

import 'package:syntax_core/langs/dart.dart';
import 'package:syntax_core/syntax.dart';
import 'package:syntax_core/themes/github_dark.dart';

const code = '''
void main() {
  // Greets the world.
  print('Hello, world!');
}
''';

void main() {
  final highlighter = Highlighter(languages: [dartLanguage]);

  // Colored output for a terminal.
  print(highlighter.toAnsi(code, language: 'dart', theme: githubDarkTheme));

  // Or styled ranges over the text, to paint with any renderer.
  final ranges = highlighter.highlightRanges(
    code,
    language: 'dart',
    theme: githubDarkTheme,
  );
  for (final range in ranges) {
    final text = code.substring(range.start, range.end);
    print('${colorToHex(range.style.foreground)}  $text');
  }

  // Or a diff, laid out as the rows a diff view shows.
  final diff = diffTexts(
    code,
    code.replaceFirst('Greets the world', 'Says hello'),
  );
  for (final row in layoutDiff([diff])) {
    print(row);
  }
}
0
likes
150
points
0
downloads

Documentation

API reference

Publisher

verified publisherconcepta.dev

Weekly Downloads

TextMate-grammar syntax highlighting in pure Dart. Tokenizes code with VS Code grammars and themes and renders tokens, diffs, HTML, or ANSI. No Flutter required.

Topics

#syntax-highlighting #textmate #code #highlighter

License

BSD-3-Clause (license)

More

Packages that depend on syntax_core