Markwon icon indicating copy to clipboard operation
Markwon copied to clipboard

Guidance for highlighting search text inside markdown text

Open pramodshri opened this issue 3 years ago • 1 comments

  • Markwon version: 4.6.2

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!

pramodshri avatar Aug 23 '21 07:08 pramodshri

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);

noties avatar Aug 26 '21 09:08 noties