commonmark-java icon indicating copy to clipboard operation
commonmark-java copied to clipboard

Internal space line is trimmed in converted plaintext

Open Goooler opened this issue 1 year ago • 1 comments

Convert markdown to plaintext using:

private fun convertMarkdownToPlaintext(markdown: String): String {
    val parser = Parser.builder().build()
    val document = parser.parse(markdown)
    val renderer = TextContentRenderer.builder().build()
    return renderer.render(document)
}

Example:

this
is 

**note**

Expected behavior:

Expected plaintext:

this
is

note

Actual plaintext:

this
is
note

(Also see what the reference implementation does: https://spec.commonmark.org/dingus/)

Goooler avatar Aug 06 '24 10:08 Goooler

您好!邮件已收到。

boyshell avatar Aug 06 '24 10:08 boyshell

The plain text renderer is not really well-defined. But this is something we might change (CC @JinneeJ). Out of interest, what are you using it for?

robinst avatar Sep 12 '24 14:09 robinst

I use this to convert markdown from a rich text editor on Android.

Goooler avatar Sep 13 '24 00:09 Goooler

Ah this came up in https://github.com/commonmark/commonmark-java/issues/264 as well. Happy to accept a patch for this as an option on TextContentRenderer.Builder.

robinst avatar Sep 18 '24 08:09 robinst

Closing as a duplicate of #264

robinst avatar Sep 24 '24 08:09 robinst