highlight To Html
Highlights code and returns raw HTML with <span class="hljs-*"> tokens, together with the time taken for the JavaScript round-trip.
Lower-level alternative to highlight: use this when you need the raw HTML string rather than a theme-applied AnnotatedString. Automatically initializes the WebView on the first call. Thread-safe: may be called from any dispatcher.
engine.highlightToHtml("val x = 42", "kotlin").onSuccess { result ->
// result.html contains e.g. <span class="hljs-keyword">val</span> x = ...
renderRawHtml(result.html)
log("JS round-trip: ${result.durationMs} ms")
}Content copied to clipboard
Return
Result wrapping an HtmlHighlightResult (html + timing), or Result.failure with a HighlightException on error. Returns HighlightException.Timeout if the JavaScript call does not complete within the timeout window.
Parameters
code
The source code to highlight.
language
Highlight.js language identifier (e.g. "kotlin", "python").