MarkdownText

fun MarkdownText(content: String, modifier: Modifier = Modifier, style: TextStyle = MaterialTheme.typography.bodySmall, color: Color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines: Int = Int.MAX_VALUE)(source)

Lightweight inline Markdown renderer for Jetpack Compose.

Efficiently parses and renders basic inline formatting styles:

Block Flattening & Line Clamping

Headings (#), bullet lists (- , * ), and numbered items (1. ) are flattened onto continuous lines to guarantee that parent layout line clamping (maxLines with TextOverflow.Ellipsis) works deterministically.

This matches the rendering behavior used across CupThread iOS/macOS SDKs and web dashboards for ChangelogEntry.body and FeatureRequestItem.description.

Example Usage

@Composable
fun ChangelogSnippet(entry: ChangelogEntry) {
MarkdownText(
content = entry.body,
maxLines = 3,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface
)
}

Parameters

content

Raw Markdown string to parse and format.

modifier

Optional Modifier for the text layout.

style

Base TextStyle for the rendered text; defaults to bodySmall.

color

Text color for regular text; links are styled in MaterialTheme.colorScheme.primary.

maxLines

Maximum number of lines before truncating with an ellipsis.