Skip to content

A Kotlin Multiplatform library to render HTML content as Compose AnnotatedString, supporting basic formatting and hyperlinks.

License

Notifications You must be signed in to change notification settings

ch4rl3x/HtmlText

Repository files navigation

Build CodeFactor Maven Central

HtmlText

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. HtmlText has been made accessible for screen readers and keyboard operation.

Warning

Starting with version 3.0.0-beta02, the Maven GroupId has changed to de.charlex.compose and artifact names changed from material-html-text to html-text-material.

Note

🚀 HtmlText is now Compose Multiplatform

Supported HTML tags

Tag Description
<b> Bold text
<i> Italic text
<strike> Strikethrough text
<u> Underlined text
<ul> Unordered list
<ol start="3" type="1"> Ordered list (a., A., 1.)
<li> List item
<a href="..."> Clickable link
<span style="color: #0000FF"> Colored text
<span style="color: rgb(r,g,b)"> Colored text
<font color="#FF0000"> Colored text
<font color="rgb(r,g,b)"> Colored text

MaterialTheme colors in HtmlText

To use colors like MaterialTheme.colors.primary in HtmlText, map simple colors.

HtmlText(
    stringId = R.string.hello_world_cdata,
    colorMapping = mapOf(Color.Red to MaterialTheme.colors.primary)
)
<resources>
    <string name="hello_world_escaped">Hello &lt;span style="color: #FF0000"&gt;World&lt;/span&gt;</string>
    <string name="hello_world_cdata"><![CDATA[Hello <span style="color: #FF0000">World</span>]]></string>
</resources>

Preview

HtmlText

Dependency

Add actual HtmlText library:

dependencies {
    implementation 'de.charlex.compose:html-text-material:3.0.0-beta02'
}

or

dependencies {
    implementation 'de.charlex.compose:html-text-material3:3.0.0-beta02'
}

License

Copyright 2025 Alexander Karkossa

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A Kotlin Multiplatform library to render HTML content as Compose AnnotatedString, supporting basic formatting and hyperlinks.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •