|
1 | | -<a href="https://github.com/ch4rl3x/HtmlText/actions?query=workflow%3ABuild"><img src="https://github.com/ch4rl3x/HtmlText/workflows/build.yml/badge.svg" alt="Build"></a> |
| 1 | +<a href="https://github.com/ch4rl3x/HtmlText/actions?query=workflow%3ABuild"><img src="https://github.com/ch4rl3x/HtmlText/actions/workflows/build.yml/badge.svg" alt="Build"></a> |
2 | 2 | <a href="https://www.codefactor.io/repository/github/ch4rl3x/HtmlText"><img src="https://www.codefactor.io/repository/github/ch4rl3x/HtmlText/badge" alt="CodeFactor" /></a> |
| 3 | +<a href="https://repo1.maven.org/maven2/de/charlex/compose/material3/material3-html-text/"><img src="https://img.shields.io/maven-central/v/de.charlex.compose.material3/material3-html-text" alt="Maven Central" /></a> |
3 | 4 |
|
4 | | -| Material | Material 3 | |
5 | | -|-----|------------| |
6 | | -| <a href="https://repo1.maven.org/maven2/de/charlex/compose/material/material-html-text/"><img src="https://img.shields.io/maven-central/v/de.charlex.compose.material/material-html-text" alt="Maven Central" /></a> | <a href="https://repo1.maven.org/maven2/de/charlex/compose/material3/material3-html-text/"><img src="https://img.shields.io/maven-central/v/de.charlex.compose.material3/material3-html-text" alt="Maven Central" /></a> | |
7 | 5 |
|
8 | 6 | # HtmlText |
9 | 7 |
|
10 | 8 | `HtmlText` is a Kotlin Multiplatform library that allows you to render HTML content as Compose `AnnotatedStrings. It supports basic formatting, hyperlinks, and color styling in a multiplatform-friendly way. |
11 | 9 |
|
12 | 10 | > [!NOTE] |
13 | | -> 🚀 RevealSwipe is now Compose Multiplatform |
| 11 | +> 🚀 HtmlText is now Compose Multiplatform |
14 | 12 |
|
15 | 13 | ## Supported HTML tags |
16 | 14 |
|
|
34 | 32 | To use colors like `MaterialTheme.colors.primary` in `HtmlText`, map simple colors. |
35 | 33 | ```kotlin |
36 | 34 | HtmlText( |
37 | | - textId = R.string.hello_world, |
| 35 | + stringId = R.string.hello_world_cdata, |
38 | 36 | colorMapping = mapOf(Color.Red to MaterialTheme.colors.primary) |
39 | 37 | ) |
40 | 38 | ``` |
41 | 39 | ```xml |
42 | 40 | <resources> |
43 | | - <string name="hello_world">"Hello <span style="color: red">World</span>"</string> |
44 | | -</resources> |
45 | | -``` |
46 | | - |
47 | | -## String arguments in HtmlText |
48 | | -To use string arguments with `HtmlText`, use CDATA |
49 | | -```kotlin |
50 | | -HtmlText( |
51 | | - text = stringResource(R.string.hello_world, "Hello") |
52 | | -) |
53 | | -``` |
54 | | -```xml |
55 | | -<resources> |
56 | | - <string name="hello_world"><![CDATA[%1$s World]]></string> |
57 | | -</resources> |
58 | | -``` |
59 | | - |
60 | | -## Combine MaterialTheme colors and string arguments in HtmlText |
61 | | -You can combine colorMapping with string arguments (CDATA) and all other HTML tags. If you use CDATA, you have to escape double quotes. |
62 | | -```xml |
63 | | -<resources> |
64 | | - <string name="hello_world"><![CDATA[Hello <span style=\"color: red\">World</span>]]></string> |
| 41 | + <string name="hello_world_escaped">Hello <span style="color: #FF0000">World</span></string> |
| 42 | + <string name="hello_world_cdata"><![CDATA[Hello <span style="color: #FF0000">World</span>]]></string> |
65 | 43 | </resources> |
66 | 44 | ``` |
67 | 45 |
|
| 46 | +## Preview |
68 | 47 |
|
| 48 | + |
69 | 49 |
|
70 | 50 | ## Dependency |
71 | 51 |
|
72 | 52 | Add actual HtmlText library: |
73 | 53 |
|
74 | 54 | ```groovy |
75 | 55 | dependencies { |
76 | | - implementation 'de.charlex.compose.material:material-html-text:2.1.0-beta01' |
| 56 | + implementation 'de.charlex.compose.material:material-html-text:3.0.0-beta01' |
77 | 57 | } |
78 | 58 | ``` |
79 | 59 |
|
80 | 60 | or |
81 | 61 |
|
82 | 62 | ```groovy |
83 | 63 | dependencies { |
84 | | - implementation 'de.charlex.compose.material3:material3-html-text:2.1.0-beta01' |
| 64 | + implementation 'de.charlex.compose.material3:material3-html-text:3.0.0-beta01' |
85 | 65 | } |
86 | 66 | ``` |
87 | 67 |
|
88 | | -## How does it work? |
89 | | - |
90 | | -Use it like a normal Text composable |
91 | | - |
92 | | -```kotlin |
93 | | -HtmlText(textId = R.string.hello_world) |
94 | | -``` |
95 | | - |
96 | | -```xml |
97 | | -<resources> |
98 | | - <string name="hello_world">Hello <b>World</b>. This <i><strike>text</strike>sentence</i> is form<b>att<u>ed</u></b> in simple html. <a href="https://github.com/ch4rl3x/HtmlText">HtmlText</a></string> |
99 | | -</resources> |
100 | | -``` |
101 | | - |
102 | | -## Preview |
103 | | - |
104 | | - |
105 | | - |
106 | | - |
107 | 68 | License |
108 | 69 | -------- |
109 | 70 |
|
|
0 commit comments