Add script to pandoc using the -A option

Viewed 427

I am trying to compile a markdown file to HTML using pandoc. I have already managed to convert the file and add a stylesheet to it, but I seem to fail to correctly add some Javascript. What I've got so far is the following command:

pandoc slides.md -o slides.html -s --section-divs -c slides.css -A slides.js

This already works pretty well, I am just bother by the fact that the -A flag seems to be able to import the slides.js file, and place it right before the closing body tag, but somehow it doesn't wrap the JS code using the script tag. Is there any way to do this? Or do I have to add the script tags in the slides.js file? That's something that would feel a bit weird.

1 Answers

Well, the -A option is short for --include-after-body, from the MANUAL:

Include contents of FILE, verbatim, at the end of the document body

so it's not specific to javascript files, that's why it behaves the way it does.

Depending on your use case, you can either use a custom template, or just use the header-includes variable in the YAML metadata header:

---
header-includes: <script src="foo"></script>
---

my markdown document

and then run pandoc --self-contained

P.S. you may be interested in https://pandoc.org/MANUAL.html#producing-slide-shows-with-pandoc

Related