Jon49
Jon49

Reputation: 4606

Retain YAML data when converting markdown to html with pandoc

Is it possible to retain the yaml header in a markdown file when converting to html using pandoc?

Or, even better, convert the yaml to json and keep it in the converted file.

E.g.,

---
title: My Title
subtitle: My Subtitle
...

# Pandoc

We Love pandoc

To:

---
title: My Title
subtitle: My Subtitle
...

<h1>Pandoc</h1>

<p>We Love pandoc</p>

Or something like:

{title: "My Title", subtitle: "My Subtitle"}

<h1>Pandoc</h1>

<p>We Love pandoc</p>

Update

So, I guess I'll use templates and do something like this:

{title: $title$, subtitle:$subtitle$}

Upvotes: 1

Views: 1423

Answers (1)

Matt
Matt

Reputation: 74660

Not out of the box as HTML doesn't have the concept of a YAML or JSON block (without javascript). You can customise your output with templates:

Templates

To see the default template that is used, just type

pandoc -D FORMAT

A custom template can be specified using the --template option. You can also override the system default templates for a given output format FORMAT by putting a file templates/default.FORMAT in the user data directory (see --data-dir

So you can create a custom template that deals with values in the YAML metadata block as you see fit.

Examples 5.11 YAML metadata block

Template variables will be set automatically from the metadata. Thus, for example, in writing HTML, the variable abstract will be set to the HTML equivalent of the markdown in the abstract field:

Upvotes: 2

Related Questions