Dart package with basic support for tokenization and syntax highlighting of various programming languages and data formats.
This package is currently experimental, not fully tested, and is still subject to large, potentially breaking changes.
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:
- C (
c) - C++ (
cpp) - Dart (
dart) - GLSL (
glsl,frag,vert,geom,comp) - 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) - Ruby (
ruby,rb) - Swift (
swift) - Text (
text,plaintext,none,txt) - XML (
xml,xhtml) - YAML (
yaml,yml)