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 copy button slot while keeping the default icon
SyntaxHighlightedCode(
code = snippet,
language = "kotlin",
copyButton = { onClick ->
SyntaxHighlightedCodeDefaults.CopyButton(
onClick = onClick,
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 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, tint: Color = LocalContentColor.current.copy(alpha = 0.7f), contentDescription: String = "Copy code", size: Dp = copyButtonSize)

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

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

Default language badge used by SyntaxHighlightedCode's languageLabel slot.