It there any api to render html in a Text? And I d...
# compose
d
It there any api to render html in a Text? And I don’t need to worry whether the content is plain text or html. Below is a screen shot from my sample and snippet what I am using to generate the view
Copy code
@Composable
fun RenderArticle(article: ArticleUIModel) {
    Divider(thickness = 8.dp, color = MaterialTheme.colors.surface)
    Surface(shape = shapes.medium, elevation = 8.dp, color = MaterialTheme.colors.surface, modifier = Modifier.fillMaxWidth()) {
        Column(modifier = Modifier.padding(8.dp)) {
            Text(
                text = article.title,
                style = MaterialTheme.typography.h6,
                color = MaterialTheme.colors.onSurface,
                modifier = Modifier.padding(bottom = 4.dp)
            )
            Divider(thickness = 2.dp, color = MaterialTheme.colors.surface)
            Text(
                text = article.description,
                style = MaterialTheme.typography.body1,
                color = MaterialTheme.colors.onSurface,
                modifier = Modifier.padding(top = 4.dp)
            )
        }
    }
    Divider(thickness = 8.dp, color = MaterialTheme.colors.surface)
}
p
You can either use AnnotatedString or WebView using AndroidView. I used the latter approach for rendering markdown here: https://www.github.com/pavi2410/jetpack_compose_test/tree/master/app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fexample%2Fjetpackcomposetest%2FMarkDownParser.kt
Or you can also use the old TextView and Html.fromHtml using AndroidView
d
Thanks @pavi2410, I didn't wanted to use the Webview or Old TextView. Will give a try with you MarkeDownParser.