AutoHighlightResult

data class AutoHighlightResult(val annotated: AnnotatedString, val detectedLanguage: String, val spanCount: Int, val durationMs: Long, val timings: HighlightTimings)

Result of a successful HighlightEngine.highlightAuto call.

This mirrors HighlightResult, but stores the language detected by Highlight.js instead of a caller-supplied language. Automatic detection is convenient for unknown snippets, but it is usually slower and less accurate than passing an explicit language.

Usage

engine.highlightAuto(code, theme).onSuccess { result ->
SyntaxHighlightedCode(
code = code,
language = result.detectedLanguage,
theme = theme,
)

log("Detected language: ${result.detectedLanguage}")
log("Highlight took ${result.durationMs} ms")
}

detectedLanguage may be an empty string if Highlight.js could not determine a language.

Constructors

Link copied to clipboard
constructor(annotated: AnnotatedString, detectedLanguage: String, spanCount: Int, durationMs: Long, timings: HighlightTimings)

Properties

Link copied to clipboard

The syntax-highlighted AnnotatedString ready for rendering.

Link copied to clipboard

Highlight.js detected language identifier, or an empty string when auto-detection could not determine one.

Link copied to clipboard

Pure highlight time in milliseconds. Equals timings.total.inWholeMilliseconds.

Link copied to clipboard

Number of AnnotatedString.spanStyles entries. A value of 0 indicates that no tokens were found.

Link copied to clipboard

Per-layer timing breakdown for this highlight call. Always populated.