highlight

suspend fun highlight(code: String, language: String, theme: HighlightTheme): Result<HighlightResult>

Full pipeline: tokenise → apply theme → convert to HighlightResult.

Combines highlightToHtml with colour-map application to produce a ready-to-render AnnotatedString. A HighlightResult.spanCount of 0 indicates a silent failure - the language may be unsupported or the code was empty; HighlightResult.annotated still contains plain text so callers can always render something.

engine.highlight(code, "kotlin", theme).onSuccess { result ->
display(result.annotated)
if (result.spanCount == 0) log("no tokens - language may be unsupported")
log("highlighted in ${result.durationMs} ms")
}

Return

Result wrapping a HighlightResult, or Result.failure with a HighlightException on error.

Parameters

code

The source code to highlight.

language

Highlight.js language identifier (e.g. "kotlin", "python").

theme

The HighlightTheme whose colour map will be applied.