Identifying tags using pandoc and YAML headers
I am writing in Markdown (with YAML header) and trying to convert to HTML using pandoc. My YAML header has a "tags" field, which is a list, as in the following example:
---
title: Title
tags: [one, two]
...
Text.
In the end result, I would like to show the tags nicely, eg. comma delimited list. However, in my pandoc template, the variable $tags$
only contains the first tag. Doing something like $for(tags)$$tags$, $endfor$
will generate all the tags, but trailing comma and space is a problem. How can I display a list of tags in the final HTML as one, two
instead of just one
or one, two,
?
source to share
I missed this in the official documentation on Templates :
When variables can have multiple values (e.g. author in a multi-author document), you can use the keyword
$for$
:
$for(author)$ <meta name="author" content="$author$" /> $endfor$
You can optionally specify a separator to be used between successive elements:
$for(author)$$author$$sep$, $endfor$
So in my case I would do $for(tags)$$tags$$sep$, $endfor$
in a template.
source to share