Markwon
Markwon copied to clipboard
Guidance for highlighting search text inside markdown text
- 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!
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);