Pandoc metadata not appearing in default HTML template

Viewed 1459

I'm converting org and markdown files to HTML using pandoc. I want to set metadata such as the title, subtitle, and author tags in an external YAML file and have them display using a template. However I can't get anything to appear beyond the normal body conversion.

I'm using the default HTML template. I've run the conversion concatenating the YAML config beforehand:

pandoc -t html -o output.html metadata.yaml input.md

I also tried including the yaml_metadata_block extension:

pandoc -t html+yaml_metadata_block -o output.html metadata.yaml input.md

Also, I've tried setting the variables in the command itself:

pandoc -t html -o output.html -V title="my title" input.md

My YAML file looks like this:

---
title: "my title"
subtitle: "my subtitle"
author: "the author"
...

Inspecting the default html template with pandoc -D html, it looks like when title etc. are defined, it'll place in a header block:

$if(title)$
<header>
<h1 class="title">$title$</h1>
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
$for(author)$
<p class="author">$author$</p>
$endfor$
$if(date)$
<p class="date">$date$</p>
$endif$
</header>

But in every case, the html file only contains the converted text from input.md. I think this is the $body$ line defined in the default template.

How can I get these fields to appear in my html document?

1 Answers

My goodness, all I was missing is the -s attribute!

from the man page:

-s, --standalone
          Produce output with an appropriate header and footer (e.g.  a standalone HTML, LaTeX, TEI, or RTF file, not a fragment).  This option is set automat‐
          ically for pdf, epub, epub3, fb2, docx, and odt output.

Thus the following command works as expected

pandoc -s -t html -o output.html metadata.yaml input.md
Related