jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.14k stars 3.35k forks source link

Markdown soft breaks are supported only when reading #9907

Closed CodeSandwich closed 3 months ago

CodeSandwich commented 3 months ago

Reading works

Pandoc handles soft breaks when reading markdown. For example:

printf "a\nb" | pandoc -f markdown -t json

Results in this, notice the SoftBreak element:

{"pandoc-api-version":[1,23,1],"meta":{},"blocks":[{"t":"Para","c":[{"t":"Str","c":"a"},{"t":"SoftBreak"},{"t":"Str","c":"b"}]}]}

Writing doesn't work

On the other hand soft breaks are dropped when writing. For example:

printf "a\nb" | pandoc -f markdown -t markdown

Results in this, notice how SoftBreak is lost, it's rendered as a space:

a b

Is this an issue?

The question is if this is an issue at all. Markdown allows breaking lines without affecting the semantics, so it's logical that they aren't preserved when writing. But if this is the case, then why is it generated when reading, shouldn't it be ignored as a markdown formatting details without any meaning? I may be missing why SoftBreak even exists in Pandoc when LineBreak is there, is it there to support preserving markdown formatting during conversions between formats supporting it?

Pandoc version?

pandoc 3.1.13 Linux

jgm commented 3 months ago

What you want is --wrap=preserve.