openai/compose-richtext

Public

mirrored fromhttps://github.com/openai/compose-richtextAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
31698d62e15def124a841935ed0bc40c64e6db88

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/richtext-markdown.md

52lines · modecode

1# Markdown
2
3[![Android Library](https://img.shields.io/badge/Platform-Android-green.svg?style=for-the-badge)](https://developer.android.com/studio/build/dependencies)
4[![JVM Library](https://img.shields.io/badge/Platform-JVM-red.svg?style=for-the-badge)](https://kotlinlang.org/docs/mpp-intro.html)
5
6Library for rendering Markdown tree that is defined as an `AstNode`. This module would be useless
7for someone who is looking to just render a Markdown string. Please check out
8`richtext-commonmark` for such features. `richtext-markdown` behaves as sort of a building block.
9You can create your own parser or use 3rd party ones that converts any Markdown string to an
10`AstNode` tree.
11
12## Gradle
13
14```kotlin
15dependencies {
16 implementation("com.halilibo.compose-richtext:richtext-markdown:${richtext_version}")
17}
18```
19
20## Rendering
21
22The simplest way to render markdown is just pass an `AstNode` to the [`BasicMarkdown`](../api/richtext-markdown/com.halilibo.richtext.markdown/-basic-markdown.html)
23composable under RichText scope:
24
25~~~kotlin
26RichText(
27 modifier = Modifier.padding(16.dp)
28) {
29 // requires richtext-commonmark module.
30 val parser = remember(options) { CommonmarkAstNodeParser(options) }
31 val astNode = remember(parser) {
32 parser.parse(
33 """
34 # Demo
35
36 Emphasis, aka italics, with *asterisks* or _underscores_. Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. [Links with two blocks, text in square-brackets, destination is in parentheses.](https://www.example.com). Inline `code` has `back-ticks around` it.
37
38 1. First ordered list item
39 2. Another item
40 * Unordered sub-list.
41 3. And another item.
42 You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
43
44 * Unordered list can use asterisks
45 - Or minuses
46 + Or pluses
47 """.trimIndent()
48 )
49 }
50 BasicMarkdown(astNode)
51}
52~~~
53