noties / Markwon

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

LastLineSpacingSpan applies spacing on each list item when used on a Paragraph Node #410

Closed pramod-knidal closed 1 year ago

pramod-knidal commented 1 year ago
  1. Please specify expected/actual behavior

Expected : Using LastLineSpacingSpan on a Paragraph node should add spacing only after paragraph texts. Actual : LastLineSpacingSpan adds spacing even after ListItems

  1. Please specify conditions/steps to reproduce (layout, code, markdown used, etc)

Add the following code to the Markwon builder :

 private val paraEndSpacingPlugin =
    object : AbstractMarkwonPlugin() {
      override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) {
        val paragraphSpacing =
          appContext.resources.getDimension(R.dimen.markwon_paragraph_spacing).toInt()
                builder.appendFactory(Paragraph::class.java) { _, _ ->
                  LastLineSpacingSpan(paragraphSpacing)
                }
      }
    }

val  markwon = 
    Markwon.builder(sAppContext)
        .usePlugin(CorePlugin.create())
        .usePlugin(paraEndSpacingPlugin)
        .build()

and use that markwon to render text paragraphs and lists. See that the list item spacing would also have increased.

noties commented 1 year ago

Hello @pramodshri-tgsys ,

there seems to be a confusion about paragraphs. Here a Paragraph represents a commonmark node, which is not always the same as a text paragraph. You can inspect the dingus AST tab to see that each list item has a paragraph child.

Thus, if you are applying LastLineSpacingSpan for a Paragraph node - each list item would have line spacing after it - as each of them contains a Paragraph