Dart package with basic support for tokenization and syntax highlighting of various programming languages and data formats.
This package is currently experimental, untested, and expected to change heavily.
To use package:opal and access its language tokenization support,
first add it as a dependency in your pubspec.yaml file:
dart pub add opalThe package contains one library:
package:opal/opal.dart
To tokenize text with a known language that has built-in support,
access the language from BuiltInLanguages:
import 'dart:convert';
import 'package:opal/opal.dart';
void main() {
final dart = BuiltInLanguages.dart;
final tokens = dart.tokenize(
const LineSplitter().convert('''
void main() {
print('hi!');
}
'''),
);
print(tokens);
}Currently the following languages are supported with the specified default and alternative IDs:
- Dart (
dart) - Groovy (
groovy,gradle) - HTML (
html) - Java (
java) - JavaScript (
javascript,js) - JSON (
json) - Kotlin (
kotlin,kt) - Markdown (
markdown,md) - Objective-C (
objective-c,objectivec,obj-c,objc) - Swift (
swift) - Text (
text,plaintext,none,txt) - XML (
xml,xhtml) - YAML (
yaml,yml)