maxpe
maxpe

Reputation: 316

How to stop pandoc from escaping underscores?

I use pandoc to create a website version of my CV. The data used is stored in a YAML file. It works smoothly except that some hyperlinks are broken because pandoc escapes underscores. Is there any way to stop it from doing that?

I tried some extension like 'tex_math_dollars' and 'tex_subscript' but enabling these doesn't prevent escaped underscores. I couldn't find any answers in pandoc's documentation for this specific question.

A minimal example:

The YAML file (example.md):

---
url: http://some.url/with_an_underscore
---

The template file (template.md):

$url$ 

Call to pandoc:

pandoc example.md --to markdown --from markdown --output out.md --template template.md

Resulting output (out.md):

http://some.url/with\_an\_underscore

Upvotes: 2

Views: 2426

Answers (1)

mb21
mb21

Reputation: 39189

YAML metadata fields are parsed as Markdown. As such, the same thing is happening to you as in the following example:

$ echo 'http://some.url/with_an_underscore' | pandoc -t markdown
http://some.url/with\_an\_underscore

Pandoc is just overly cautious when escaping underscores in markdown output, because it might be italics. But the output is perfectly valid markdown. (Try converting it to HTML to see what I mean.)

Maybe the question is: why are you converting from markdown to markdown and are bothered by the escaped underscores?

If you absolutely must, you can circumvent the reserialization by using a raw_attribute:

---
url: |
  ```{=markdown}
  http://some.url/with_an_underscore
  ```
---

Upvotes: 3

Related Questions