Package-level declarations

Types

Link copied to clipboard
data class CodeBlockStyle(val shape: Shape = SyntaxHighlightedCodeDefaults.shape, val padding: PaddingValues = SyntaxHighlightedCodeDefaults.padding, val headerPadding: PaddingValues = SyntaxHighlightedCodeDefaults.headerPadding, val lineNumberColor: Color = Color.Unspecified, val lineNumberWidth: Dp = SyntaxHighlightedCodeDefaults.lineNumberWidth, val copyButtonSize: Dp = SyntaxHighlightedCodeDefaults.copyButtonSize, val textStyle: TextStyle = SyntaxHighlightedCodeDefaults.codeTextStyle, val fallbackBackgroundColor: Color = SyntaxHighlightedCodeDefaults.fallbackBackgroundColor, val fallbackTextColor: Color = SyntaxHighlightedCodeDefaults.fallbackTextColor)

Visual style configuration for SyntaxHighlightedCode.

Link copied to clipboard
@RequiresOptIn(message = "This API is part of the experimental compose-highlight surface and may change or be removed in future releases without a deprecation cycle.", level = RequiresOptIn.Level.ERROR)
annotation class ExperimentalHighlightApi

Marks an API as experimental within the compose-highlight library.

Link copied to clipboard

Default values and helper composables used by SyntaxHighlightedCode and CodeBlockStyle.

Properties

Link copied to clipboard
Link copied to clipboard

CompositionLocal that provides the active HighlightTheme to all SyntaxHighlightedCode composables in the subtree.

Link copied to clipboard

Functions

Link copied to clipboard
fun HighlightThemeProvider(darkTheme: Boolean = isSystemInDarkTheme(), lightHighlightTheme: HighlightTheme = rememberTomorrowTheme(), darkHighlightTheme: HighlightTheme = rememberTomorrowNightTheme(), content: @Composable () -> Unit)

Provides HighlightTheme and a shared HighlightEngine to all SyntaxHighlightedCode composables in content.

Link copied to clipboard

Creates and remembers the built-in Atom One Dark HighlightTheme.

Link copied to clipboard

Creates and remembers the built-in Atom One Light HighlightTheme.

Link copied to clipboard
fun rememberHighlightedCode(code: String, language: String, theme: HighlightTheme = LocalHighlightTheme.current, onHighlightComplete: (HighlightResult) -> Unit? = null, onError: (HighlightException) -> Unit? = null): State<AnnotatedString?>

Pre-highlights code and remembers the resulting AnnotatedString.

Link copied to clipboard
fun rememberHighlightedCodeBothThemes(code: String, language: String, lightTheme: HighlightTheme = LocalLightHighlightTheme.current, darkTheme: HighlightTheme = LocalDarkHighlightTheme.current, onHighlightComplete: (ThemedHighlightResult) -> Unit? = null, onError: (HighlightException) -> Unit? = null): State<ThemedHighlightResult?>

Pre-highlights code for both light and dark themes in a single JS call.

Link copied to clipboard

Creates and remembers a HighlightEngine scoped to the composition.

Link copied to clipboard
fun rememberSyntaxHighlightedEditorValue(value: TextFieldValue, language: String, theme: HighlightTheme = LocalHighlightTheme.current, debounceMs: Long = SyntaxHighlightedTextEditorDefaults.DEBOUNCE_MS, onHighlightComplete: (AnnotatedString) -> Unit? = null, onError: (HighlightException) -> Unit? = null): TextFieldValue

Runs the debounce + syntax-highlight pipeline for a live code editor and returns the display TextFieldValue ready to pass directly to BasicTextField (or any other text field that accepts TextFieldValue).

Link copied to clipboard

Creates and remembers the built-in Base16 Tomorrow Night (dark) HighlightTheme.

Link copied to clipboard

Creates and remembers the built-in Base16 Tomorrow (light) HighlightTheme.

Link copied to clipboard
fun SyntaxHighlightedCode(code: String, language: String, modifier: Modifier = Modifier, theme: HighlightTheme = LocalHighlightTheme.current, style: CodeBlockStyle = CodeBlockStyle.Default, showLineNumbers: Boolean = false, languageLabel: @Composable () -> Unit? = if (language.isNotBlank()) DefaultLanguageLabelSentinel else null, copyButton: @Composable (onClick: () -> Unit) -> Unit? = DefaultCopyButtonSentinel, onCopyClick: (String) -> Unit? = null, onHighlightComplete: (HighlightResult) -> Unit? = null, onError: (HighlightException) -> Unit? = null, placeholder: @Composable (code: String) -> Unit? = null)

Displays syntax-highlighted code in a styled block.

Link copied to clipboard
fun SyntaxHighlightedTextEditor(value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, language: String, modifier: Modifier = Modifier, contentPadding: PaddingValues = PaddingValues(0.dp), shape: Shape = RectangleShape, theme: HighlightTheme = LocalHighlightTheme.current, textStyle: TextStyle = SyntaxHighlightedTextEditorDefaults.DefaultTextStyle, debounceMs: Long = SyntaxHighlightedTextEditorDefaults.DEBOUNCE_MS, onHighlightComplete: (AnnotatedString) -> Unit? = null, onError: (HighlightException) -> Unit? = null)

This composable is marked experimental (ExperimentalHighlightApi). Call sites must opt in with @OptIn(ExperimentalHighlightApi::class) or propagate the annotation. The API surface (parameters, defaults, behavior) may change in future releases.