Markwon linkify in a composable Text

1.3k Views Asked by At

In Android using jetpack-compose, is there currently a way to display a text containing links in a @Composable Text?

In legacy TextView, we used Markwon with linkify plugin. Markwon creates a Spanned object that we can set into the TextView's text.

Is there a way to proceed with the same with @Composable Text? Or do we have to use a legacy TextView embedded within a @Composable AndroidView?

Thank you

2

There are 2 best solutions below

2
nglauber On BEST ANSWER

I think this library can help you: https://github.com/jeziellago/compose-markdown

Add the repository to the project's build.gradle.

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' } // add this
    }
}

Then, add the dependency to the module's build.gradle

implementation 'com.github.jeziellago:compose-markdown:0.2.0'

and finally, you can use the library as follows:

MarkdownText(
    markdown = "Click [here](http://www.google.com) or http://www.stackoverflow.com."
)

In this sample, both links are detected.

0
Kitesurfer On

Still used the old Markwon and used the AndroidView Composeable to display an legacy TextView in my case, you can pass around a Spanned object and set on the TextView. The Linkify Plugin should work too