SyntaxHighlightedCodeDefaults

Default values and helper composables used by SyntaxHighlightedCode and CodeBlockStyle.

Expose constants so callers can build on them without hard-coding magic numbers, and helper composables so callers can compose on top of the built-in defaults:

// Use the library default text style with only fontSize overridden
val myStyle = CodeBlockStyle(
textStyle = SyntaxHighlightedCodeDefaults.codeTextStyle.copy(fontSize = 15.sp),
)

// Start from Compact but widen the line-number gutter
val myCompact = CodeBlockStyle.Compact.copy(
lineNumberWidth = SyntaxHighlightedCodeDefaults.lineNumberWidth + 16.dp,
)

// Customise the actions slot while keeping the default copy button
SyntaxHighlightedCode(
code = snippet,
language = "kotlin",
actions = { onCopy ->
SyntaxHighlightedCodeDefaults.CopyButton(
onClick = onCopy,
contentDescription = stringResource(R.string.copy_code),
)
},
)

Properties

Link copied to clipboard

Default TextStyle applied to the code text: monospace font, 13 sp size, 20 sp line height.

Link copied to clipboard

Default size (width and height) of the copy button.

Link copied to clipboard

Default background color used when the active theme CSS has no .hljs { background: ... } rule. Matches the dark background from the built-in tomorrow-night and atom-one-dark themes.

Link copied to clipboard

Default text color used when the active theme CSS has no .hljs { color: ... } rule. Provides readable light-gray text on the dark fallbackBackgroundColor.

Link copied to clipboard

Default padding for the header row (language label + copy button).

Link copied to clipboard

Default minimum width reserved for the line-number gutter.

Link copied to clipboard

Default inner padding for the code content area.

Link copied to clipboard

Default corner radius for the code block container.

Functions

Link copied to clipboard
fun CopyButton(onClick: () -> Unit, modifier: Modifier = Modifier, tint: Color = LocalContentColor.current.copy(alpha = 0.7f), contentDescription: String = "Copy code", size: Dp = copyButtonSize)

Default copy-to-clipboard button used by SyntaxHighlightedCode's actions slot.

Link copied to clipboard
fun Header(languageLabel: @Composable () -> Unit?, actions: @Composable RowScope.(onCopy: () -> Unit) -> Unit?, onCopy: () -> Unit, modifier: Modifier = Modifier, padding: PaddingValues = headerPadding)

Default header layout used by SyntaxHighlightedCode's header slot: the language label on the left, the trailing actions on the right.

Link copied to clipboard
fun LanguageLabel(language: String, modifier: Modifier = Modifier, color: Color = LocalContentColor.current.copy(alpha = 0.6f), fontSize: TextUnit = 12.sp)

Default language badge used by SyntaxHighlightedCode's languageLabel slot.