jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.88k stars 3.39k forks source link

Pandoc 1.16 emits "true" in document text when parsing metadata containing `toc: true` #2655

Closed rbdixon closed 8 years ago

rbdixon commented 8 years ago

When building my markdown document I observed a spurious "true" at the start of the document. I whittled the document down till I found this minimal example:

$ pandoc -s -o - -t markdown x.yml 

---
x: True
...

$ pandoc -s -o - -t markdown toc.yml

---
toc: True
...

true

$ exit

x.yml has a key x set to true and works as I would expect it. toc.yml has a key toc set to true and demonstrates a surprising behavior. Why is that "true" in the document output?

I'm aware that toc is a variable set by pandoc based on the --toc command line parameter. I was attempting to make the table of contents generation controllable by inserting toc: true in a YAML metadata block. If that's not a good idea let me know... but I still was not expecting true to pop up in the document output. Seems like a bug.

All files and pandoc version details: https://gist.github.com/rbdixon/9885f6bad6584b52196d

rbdixon commented 8 years ago

Hmmm.... I'd never considered that there was a template for generating markdown!

https://github.com/jgm/pandoc-templates/blob/master/default.markdown shows:

$if(titleblock)$
$titleblock$

$endif$
$for(header-includes)$
$header-includes$

$endfor$
$for(include-before)$
$include-before$

$endfor$
$if(toc)$
$toc$

$endif$
$body$
$for(include-after)$

$include-after$
$endfor$

If there is a toc variable, then show it. Not a bug, closing. Sorry. :)