https://github.com/beeper/matrix-messageformat-compose
Kotlin multiplatform library for rendering formatted Matrix message contents in Jetpack Compose
https://github.com/beeper/matrix-messageformat-compose
Last synced: 2 months ago
JSON representation
Kotlin multiplatform library for rendering formatted Matrix message contents in Jetpack Compose
- Host: GitHub
- URL: https://github.com/beeper/matrix-messageformat-compose
- Owner: beeper
- License: mit
- Created: 2026-01-16T16:33:06.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-04-11T17:53:37.000Z (2 months ago)
- Last Synced: 2026-04-11T19:26:43.472Z (2 months ago)
- Language: Kotlin
- Size: 163 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.jitpack.io/#beeper/matrix-messageformat-compose)
# matrix-messageformat-compose
Kotlin multiplatform library to translate Matrix [formatted body](https://spec.matrix.org/unstable/client-server-api/#mroommessage-msgtypes) from HTML to `AnnotatedString` for native rendering in Jetpack Compose.
## Usage
Minimal working example:
```
val parseResult = remember(textInput) {
MatrixHtmlParser().parse(
input = textInput,
style = MatrixBodyPreFormatStyle(),
allowRoomMention = true,
)
}
MatrixStyledFormattedText(
parseResult = parseResult,
inlineContent = parseResult.inlineImages.toInlineContent(
LocalDensity.current,
defaultHeight = 20.sp
) { info, modifier ->
// Your inline image rendering logic here
AsyncImage(
model = info.uri,
contentDescription = info.alt ?: info.title,
modifier = modifier,
)
},
)
```
It is recommended to move `MatrixHtmlParser().parse()` from above example out of the UI thread
into some preprocessing logic, since that's the most expensive part and does not apply any
density or theme-specific styling yet.
You can customize rendering by following means:
- `MatrixBodyPreFormatStyle`: Provides some overrides for the pre-processing step, that are not related to screen density or theme yet.
- `MatrixBodyDrawStyle`: Holds callbacks to be executed in a `DrawScope` for drawing behind certain spans, e.g. for background rendering for code blocks and similar.
- `MatrixBodyStyledFormatter`: abstract class that applies styling to the preprocessed `AnnotatedString`, that has been deferred from the initial step in order to allow styling from a compose context without the overhead of the full parser running.
You can implement this class manually, or start off of `DefaultMatrixBodyStyledFormatter` to only extend what you want to change from the provided defaults.