noties / Markwon

Android markdown library (no WebView)
https://noties.io/Markwon/
Apache License 2.0
2.74k stars 309 forks source link

Guidance for highlighting search text inside markdown text #368

Open pramodshri opened 3 years ago

pramodshri commented 3 years ago

So, we are implementing a search feature and we want to highlight part of the text (the search text) with a Background Span. I am here to get some guidance on how I can inject a span to the Markwon text. I see that the toMarkdown() method returns a Spanned object which doesn't give us any options to set more spans on it.

Looking forward to hearing from you!

noties commented 3 years ago

Hello @pramodshri ,

this is true - Spanned is returned in the API. In fact it is actually SpannableStringBuilder, so you could cast to a Spannable. I know it doesn't look like a good solution, but this is what we have now. With a safety in mind the code could be:

final Spannable spannable = spanned instanceof Spannable
        ? (Spannable) spanned
        : new SpannableString(spanned);