Skip to content

About

Simple lightweight library that leverages JS bridge to bring fast syntax highlighting to Android Jetpack Compose

Topics

Resources

Stars

31 stars

Watchers

0 watching

Forks

Repository files navigation

CI codecov release Maven Central Android Weekly

Compose Code Highlight Logo Compose Highlight for Android

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.

📚 Full documentation →

Install

dependencies {
    implementation("dev.hossain:compose-highlight:0.40.0")
}

Quick Start

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",
    )
}

Demo

📊 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

Production App Demo

See it in action in the google-play CodeMateX app's code block settings.

CodeMateX Demo

Links

License

MIT

About

Simple lightweight library that leverages JS bridge to bring fast syntax highlighting to Android Jetpack Compose

Topics

Resources

Stars

31 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages