A Jetpack Compose library for beautiful syntax highlighting - powered by
Highlight.js running in a hidden WebView, converting tokenised HTML to
native Compose AnnotatedString. Supports 190+ languages with no custom lexers to maintain.
dependencies {
implementation("dev.hossain:compose-highlight:0.40.0")
}Wrap your UI hierarchy in HighlightThemeProvider, then use any of the three built-in composables:
HighlightThemeProvider(
lightHighlightTheme = rememberTomorrowLightTheme(),
darkHighlightTheme = rememberTomorrowNightTheme(),
) {
// 1. Static Code Block (for docs, snippets, guides)
SyntaxHighlightedCode(
code = "data class Config(val enableHighlight: Boolean = true)",
language = "kotlin",
showLineNumbers = true,
)
// 2. Real-time / LLM Streaming Code Block (zero-flicker progressive rendering)
StreamingSyntaxHighlightedCode(
code = streamedText,
language = "typescript",
showLineNumbers = true,
)
// 3. Interactive Code Editor (debounced inline syntax highlighting)
var editorValue by remember { mutableStateOf(TextFieldValue("val x = 42")) }
SyntaxHighlightedTextEditor(
value = editorValue,
onValueChange = { editorValue = it },
language = "kotlin",
)
}📊 Performance: Cold start ~120-180ms & warm start ~8-20ms, see more details and comparison here. Or, use the performance check UI in sample app 📱
| Sample App | All Themes |
|---|---|
2026-06-06.16.21.49.mp4 |
2026-06-06.16.23.30.mp4 |
See it in action in the
CodeMateX app's code block settings.
- 📚 Docs: github.io/android-compose-highlight/
- 🔖 API Reference: github.io/android-compose-highlight/api/
- 📝 Blog: hossain.dev/syntax-highlighting-on-android-highlight-js-native-compose-engine/
- 📱 Sample App: sample [⬇️ APK]
- ✨ Compare Other Libs: github.com/android-syntax-highlighter-compose
MIT