使用 -A 选项将脚本添加到 pandoc

Add script to pandoc using the -A option

我正在尝试使用 pandoc 将降价文件编译为 HTML。我已经设法转换文件并向其添加样式表,但我似乎无法正确添加一些 Javascript。到目前为止我得到的是以下命令:

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

这已经很好用了,我只是对 -A 标志似乎能够导入 slides.js 文件并将其放在结束 body 标记之前这一事实感到困扰,但不知何故,它没有使用 script 标签包装 JS 代码。有什么办法吗?或者我是否必须在 slides.js 文件中添加 script 标签?这会让人觉得有点奇怪。

嗯,-A 选项是 --include-after-body 的缩写,来自手册:

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

所以它不是特定于 javascript 个文件,这就是它的行为方式的原因。

根据您的用例,您可以在 YAML 元数据 header:

中使用 custom template, or just use the header-includes variable
---
header-includes: <script src="foo"></script>
---

my markdown document

然后是运行pandoc --self-contained

P.S。您可能对 https://pandoc.org/MANUAL.html#producing-slide-shows-with-pandoc

感兴趣