Stopping Pandoc from escaping single quotes when converting from HTML to Markdown
Asked Answered
B

1

16

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.

Botticelli answered 8/12, 2018 at 0:21 Comment(1)
Googlers: E28099Blubber
D
15

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.

Decurion answered 8/12, 2018 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.