Pandoc: no line wrapping when converting to HTML

2019-07-20 17:35发布

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!

2条回答
爷的心禁止访问
2楼-- · 2019-07-20 18:06

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>
...
查看更多
爷的心禁止访问
3楼-- · 2019-07-20 18:27

It is not clear what text should get wrapped but does not as you did not provide a sample.

Pandoc supports several line breaking scenarios in markdown documents.

What you may be looking for is the hard_line_breaks extension

If it is so then your command should look like

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

I'd recommend you to read about all the markdown-relevant options and configure pandoc to match your input markdown flavor

查看更多
登录 后发表回答