I‘ve got a Pandoc (v1.19.2.1) HTML5 template that I’m loading from the default --data-dir
. Within the template I need to load external resources, such as stylesheets and JavaScript. I’d like to load those resources relative to the path of the template, not the working directory or the source file. For example, on macOS, in ~/.pandoc/templates/hierarchical/hierarchical.html
:
…
<link rel="stylesheet" href="hierarchical.css">
…
where hierarchical.css
is located at ~/.pandoc/templates/hierarchical/hierarchical.css
, in the same directory as the template itself.
Then invoked from the command line:
pandoc \
--from=markdown_strict+header_attributes+yaml_metadata_block+pipe_tables\
--to=html5 \
--self-contained \
--template="hierarchical/template.html" \
--section-divs \
--output="$1.html" \
--toc \
--toc-depth=6 \
"$1.md"
I get the error:
pandoc: Could not fetch hierarchical.css
hierarchical.css: openBinaryFile: does not exist (No such file or directory)
I’ve tried various other relative paths to the CSS file. The only thing that works is the absolute path /Users/jmakeig/.pandoc/templates/hierarchical/hierarchical.css
, which, of course, will only work on my laptop.
Is there any way to resolve external resources in Pandoc templates relative to the template itself, so that the templates are portable? I don’t see an obvious external variable that I could use in my template or a command line option.