pandocline-breaksfile-conversion

Convert from markdown to docx and keeping line break using Pandoc


I want to convert a markdown file to docx and keeping the linebreak using pandoc. the markdown look like this:

I'm a test about line break
in a docx document

And when using pandoc with the argument to preserve the wrapping I get:

I’m a test about line break in a docx document

So far I tried :

pandoc test.md --wrap=preserve -o test.docx
pandoc test.md --wrap=none -o test.docx
pandoc test.md -o test.docx

None worked.

I'm using pandoc 3.1.1 on OSX 12.3


Solution

  • The --wrap option only affects the way the text is written in the output file, but does not affect the semantic meaning of a line break. For that we need a different extension: hard_line_breaks:

    Extension: hard_line_breaks

    Causes all newlines within a paragraph to be interpreted as hard line breaks instead of spaces.

    Use with --from=markdown+hard_line_breaks.