parse method

Result parse(
  1. String source, {
  2. String? language,
  3. bool autoDetection = false,
})

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: 'dart');
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.

Implementation

Result parse(String source, {String? language, bool autoDetection = false}) {
  if (language == null) {
    if (autoDetection) {
      return _parseAuto(source);
    } else {
      throw ArgumentError.notNull('language');
    }
  }
  return _parse(source, language: language);
}