remember Highlight Engine
Creates and remembers a HighlightEngine scoped to the composition.
When called inside a HighlightThemeProvider, returns the shared engine that the provider already manages - no extra WebView is created and no extra lifecycle handling is needed.
When called outside HighlightThemeProvider (e.g. standalone usage without a provider), creates a dedicated engine that is automatically destroyed (releasing the hidden WebView) when the composable leaves the composition via DisposableEffect.
Usage
@Composable
fun MyCodeView(code: String) {
val engine = rememberHighlightEngine()
val highlighted by rememberHighlightedCode(code, "kotlin")
Text(text = highlighted ?: AnnotatedString(code))
}Content copied to clipboard
Prefer rememberHighlightedCode for simple use cases. Use rememberHighlightEngine directly only when you need lower-level control - for example, calling HighlightEngine.highlightBothThemes or reading HighlightEngine.isInitialized.