noties / Markwon

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

How to remove underline while using h1 tag in redme ? #405

Closed Groot-2001 closed 1 year ago

Groot-2001 commented 2 years ago

i am using h1 tag in readme section and at the end of the title an underline is appear, how should i get rid of that underline?

tatavarthitarun commented 2 years ago

same issue, how to remove underline for H1 and H2 ?

c-b-h commented 1 year ago

Tried this?

private class NoSpecialTreatmentOfH1H2Plugin : AbstractMarkwonPlugin() {
    override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) {
        builder.setFactory(Heading::class.java) { configuration, props ->
            HeadingSpanModified(
                configuration.theme(),
                CoreProps.HEADING_LEVEL.require(props)
            )
        }
    }
}
private class HeadingSpanModified(theme: MarkwonTheme, range: Int) : HeadingSpan(theme, range) {
    override fun drawLeadingMargin(
        c: Canvas?,
        p: Paint?,
        x: Int,
        dir: Int,
        top: Int,
        baseline: Int,
        bottom: Int,
        text: CharSequence?,
        start: Int,
        end: Int,
        first: Boolean,
        layout: Layout?
    ) {
        // NO-OP
    }
}

And creating Markwon by:

val markwon = Markwon.builder(context).usePlugin(NoSpecialTreatmentOfH1H2Plugin()).build()
noties commented 1 year ago

Hello @Groot-2001, @tatavarthitarun , @c-b-h ,

there is a heading theme attribute you can use:

val markwon = Markwon.builder(context)
  .usePlugin(object: AbstractMarkwonPlugin() {
    override fun configureTheme(builder: MarkwonTheme.Builder) {
      builder.headingBreakHeight(0)
    }
  })
  .build()