Hashtag span?
See original GitHub issue- Markwon version: {4.4.0}
Thanks for this awesome library. My life became so much easier after I wasted 2 days trying to handle bullet points, numbered lists, tables and whatnot manually 😅
However, earlier in my manual parsing, I was adding hashtag parsing (making text bold with some color) to any word preceded by # (without spaces), like “#someWord”
Is there any way to add these custom spans to the already existing markdown text? I’m using the following code to set the markdown:
var TextView?.markdownText: String?
@Deprecated(NO_GETTER, level = DeprecationLevel.ERROR) get() = noGetter()
set(value) {
this?.let { textView ->
Markwon.builder(context)
.usePlugin(StrikethroughPlugin.create())
.usePlugin(object : AbstractMarkwonPlugin() {
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
builder.linkResolver { view, link -> }
}
override fun configureTheme(builder: MarkwonTheme.Builder) {
builder
.linkColor(Color.parseColor(ACCENT_BLUE_COLOR))
.bulletWidth(dip(4))
.bulletListItemStrokeWidth(dip(1))
.listItemColor(Color.parseColor("#DE2F2F2F"))
.blockMargin(dip(20))
}
})
.usePlugin(TablePlugin.create {
it.tableBorderWidth(dip(1))
it.tableBorderColor(Color.parseColor("#E5E5E5"))
it.tableCellPadding(dip(4))
})
.build().let { markwon ->
val markdown = markwon.toMarkdown(value.orEmpty())
markwon.setParsedMarkdown(textView, markdown)
}
}
}
And this is my hashtag parsing function:
private fun SpannableStringBuilder.withHashTagHandling(): SpannableStringBuilder = apply {
if (isEmpty()) return this
Pattern.compile("""#[A-Za-z0-9!]*""").matcher(this)?.let { matcher ->
while (matcher.find()) {
matcher.group(0)?.let { hashTagString ->
setSpan(StyleSpan(Typeface.BOLD), matcher.start(), matcher.end(), SPAN_EXCLUSIVE_EXCLUSIVE)
setSpan(ForegroundColorSpan(colorCode), matcher.start(), matcher.end(), SPAN_EXCLUSIVE_EXCLUSIVE)
setSpan(RelativeSizeSpan(1.1F), matcher.start(), matcher.end(), SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
}
}
I search around in the wiki regarding hashtags, but couldn’t find anything, can you please guide me if there is a way to add the spans while setting the text?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Hashtags for #span to grow your Instagram, TikTok
Best hashtags for use with #span are #span #rokspan #rok #n #rokwanita #sp #fashion #woodporn #kunsthandwerk #basteln #holzarbeit #modernart #holzdeko ...
Read more >Best Instagram hashtags for #span | Flick: Instagram Hashtag Tool
The top 30 trending hashtags for #span ... Trending Instagram hashtags related to #span are determined by the average number of daily posts...
Read more >span Hashtags 2022 - copy and paste hashtags generator
Are you looking for span hashtags to boost likes and followers on your Instagram ... Best span hashtags popular on Instagram, Twitter, Facebook,...
Read more >Search a string for hashtags (with spaces) and wrap with spans
I'd like to search a string and wrap hashtags with spans. I found a great answer here.
Read more >#span hashtag on Instagram • Photos and Videos
104k Posts - See Instagram photos and videos from 'span' hashtag. ... Rusty Bridge #bridgmanpark #bridge #Lynncreek #span #creekcrossing #yellow #leaves.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is always room for improvement, but I find your implementation pretty solid
Okay so this is what I’ve implemented:
My
HashtagTextAddedListener
:And I’m applying this in the
configure
method like this:This approach is working, but can it be further improved?