I am using Markdown files to create a series of webpages (calling that mess a website would probably be frowned upon). I use a general template to display each page with a similar look: they all have the same header, footer, etc.
I would like to add a navigation menu, in order to have links to the other pages. I can easily generate the menu itself, what I don't know is how to insert it in the page.
What I tried is the following:
options.yml
(generated by a Python script):
metadata:
title: My very excellent title
navigation: <a href="index.html">Home</a><a href="other.html">Other page</a>
standalone: true
template: template.html
template.html
:
<!doctype HTML>
<title>$title$</title>
<header>Yeepee, header!</header>
<nav>$navigation$</nav>
<main>$body$</main>
<footer>Best footah evah</footer>
I then run the script: pandoc -d options.yml index.md -o index.html
(and same for the other files, in a loop in a Python script)
The result is that the content of my metadata.navigation
is escaped before insertion, resulting in something like <a href="index.html">Home</a><a href="other.html">Other page</a>
, which is really safe in practice, but doesn't help me there.
What I would like is to have another template, say navigation.html
, that contains the navigation menu to be included in my main template when using pandoc.
If this is not possible, I would like to use the same technique as above, but with an "unescaped" navigation
parameter (I'm not fond of it, as it would bring a major security issue into the project).
How can I achieve this?
CodePudding user response:
There are two solutions to this:
Use
variables
instead ofmetadata
in your defaults file. Variables are inserted verbatim, while metadata will be escaped.To insert the file
navigation.html
in a template, use${navigation.html()}
. Pandoc uses the doctemplates package for templates, see the docs on "partials" for more details.