Search code examples
word-wrappandoc

Pandoc: no line wrapping when converting to HTML


I am converting from Markdown to HTML like so:

pandoc --columns=70 --mathjax -f markdown input.pdc -t html -Ss > out.html

Everything works fine, except for the fact that the text doesn't get wrapped. I tried different columns lengths, no effect. Removed options, no go. Whatever I tried, the HTML just doesn't get wrapped. I search the bug tracker, but there don't seem to be any open bugs relating to this issue. I also checked the documentation, but as far as I could glean, the text ought be line-wrapped... So, have I stumbled into a bug?

I'm using pandoc version 1.12.4.2.

Thanks in advance for your help!


Solution

  • Pandoc puts newlines in the HTML so the source code is easier to read. By default, it doesn't insert <br>-tags.

    If you want to preserve line breaks from markdown input:

    pandoc -f markdown+hard_line_breaks input.md output.html
    

    However, usually a better approach to limit the text width when opening the HTML file in the browser is to adapt the HTML template (pandoc -D html5) and add some CSS, like:

    <!DOCTYPE html>
    <html$if(lang)$ lang="$lang$"$endif$>
    <head>
      <style>
      body {
         width: 46em;
      }
      </style>
    ...