highlight Both Themes
suspend fun highlightBothThemes(code: String, language: String, lightTheme: HighlightTheme, darkTheme: HighlightTheme): Result<ThemedHighlightResult>
Highlights code once and produces a ThemedHighlightResult with both a light and a dark androidx.compose.ui.text.AnnotatedString.
The JS tokeniser runs once; the two colour maps are applied to the same HTML output, so theme switching after the call returns is instant - no extra WebView round-trip.
// Inside a coroutine (e.g. viewModelScope.launch or LaunchedEffect):
engine.highlightBothThemes(
code = sourceCode,
language = "typescript",
lightTheme = HighlightTheme.tomorrow(),
darkTheme = HighlightTheme.tomorrowNight(),
).onSuccess { result ->
val display = if (isDark) result.dark else result.light
}Content copied to clipboard
Return
Result wrapping a ThemedHighlightResult, or Result.failure with a HighlightException on error.
Parameters
code
The source code to highlight.
language
Highlight.js language identifier (e.g. "kotlin", "typescript").
light Theme
Theme applied to produce ThemedHighlightResult.light.
dark Theme
Theme applied to produce ThemedHighlightResult.dark.