parse method
Parse source and returns a highlight Result which contains relevance and tree nodes.
Call Result.toHtml method to get HTML string
var result = highlight.parse(source, language: Languages.php);
var html = result.toHtml();
language: Required if autoDetection is not true.
autoDetect: The default value is false. Pass true to enable language auto detection.
Notice that this may cause performance issue because it will try to parse source with
all registered languages and use the most relevant one.
Parses source code with syntax highlighting.
Applies syntax highlighting to the provided source code based on the specified language.
If no language is provided and autoDetection is true, attempts to automatically detect
the programming language.
Parameters:
source: The source code to highlightlanguage: The programming language (required unless autoDetection is true)autoDetection: If true, attempts automatic language detection
Returns: A Result object containing highlighted nodes and language info
Throws: ArgumentError if language is null and autoDetection is false
Example:
var result = highlight.parse(
source: 'void main() { }',
language: Languages.dart,
);
Implementation
Result parse(
{required String source,
required Languages? language,
bool autoDetection = false}) {
if (language == null) {
if (autoDetection) {
return _parseAuto(source);
} else {
throw ArgumentError.notNull('language');
}
}
return _parse(source, language: language);
}