compose-highlight¶
Jetpack Compose syntax highlighting powered by Highlight.js.
Renders beautifully colored, selectable, copyable code blocks in any Compose UI - with light/dark theme support, line numbers, and full customization of the header slots.
Quick install¶
Add the dependency to your module's build.gradle.kts:
Replace <version> with the latest release.
Minimal example¶
HighlightThemeProvider {
SyntaxHighlightedCode(
code = "val greeting = \"Hello, World!\"",
language = "kotlin",
)
}
That's it. HighlightThemeProvider automatically picks Tomorrow (light) or Tomorrow Night (dark) based on the system setting.
Key features¶
- Wide language coverage - use any language supported by the bundled Highlight.js build
- Light + dark themes - automatic system-mode switching, or manual override
- Built-in themes - Tomorrow, Tomorrow Night, Atom One Dark, Atom One Light
- Custom themes - load any Highlight.js CSS from
assets/, raw CSS string, or aMap<String, SpanStyle> - Slots - replace the language badge and copy button with any composable
- Line numbers - optional gutter with configurable width and color
- Copy to clipboard - built-in, with an
onCopyClickcallback for custom feedback - Performance - one hidden WebView shared across all code blocks via
HighlightThemeProvider
Next steps¶
- Getting Started - full setup walkthrough
- API Reference - all public classes and functions
- Guides - theming, customization, line numbers, performance
- Changelog - release history