Stopping Pandoc from escaping single quotes when converting from HTML to Markdown

人走茶凉 提交于 2021-02-20 06:35:51

问题


If I convert a single quote ' from HTML to Markdown, it is automatically escaped:

 % echo "'" | pandoc -f html -t markdown
 \'

I'd like it to output without the slash, as it makes text with contractions rather much harder to read.

I thought this might be due to the "all_symbols_escapable" option, but it still happens, even when I turn that off:

% echo "'" | pandoc -f html -t markdown-all_symbols_escapable
\'

It isn't a problem, however, for markdown_strict:

% echo "'" | pandoc -f html -t markdown_strict
'

Any suggestions? I'd like to use the default Pandoc markdow with the options tweaked, or report this as a bug if it's not what others expect.


回答1:


Escaping is related to pandoc's smart extensions. This extension converts single quotes to the typographically correct opening/closing single quote or apostrophe when appropriate. This becomes most clear when looking at HTML output that uses only ASCII characters:

% echo "'hello'" | pandoc -f markdown -t html --ascii
<p>&lsquo;hello&rsquo;</p>

% echo "let's" | pandoc -f markdown -t html --ascii
<p>let&rsquo;s</p>

This smart treatment of quotes can be disabled on a per-case basis by escaping the character

% echo "let\'s" | pandoc -f markdown -t html --ascii
<p>let's</p>

or by disabling the smart extension for markdown:

% echo "let's" | pandoc -f markdown-smart -t html --ascii
<p>let's</p>

So whenever pandoc sees a ' character in HTML, it assumes that this character was chosen intentionally over the more correct single quote, and thus ensures that it won't be treated in a "smart" way when read back from Markdown.

The solution is thus to tell pandoc that it should ignore these details and will write Markdown as if it would not be subjected to the smart treatment of quotes:

% echo "'" | pandoc -f html -t markdown-smart
'

The smart extension is already disabled when using markdown_strict, which is why you got the desired behavior in that case.



来源:https://stackoverflow.com/questions/53678363/stopping-pandoc-from-escaping-single-quotes-when-converting-from-html-to-markdow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!