我正在尝试在由 markdown 文件生成的 docx 中的目录前添加一个部分。我的目录是使用 pandoc 命令的 --toc 选项生成的,而我的 markdown 没有目录字段。我尝试使用 --include-before-body 选项在目录前添加一个部分,但没有成功。
pandoc test.md -f markdown -t docx -s -o test.docx --reference-doc=./custom-reference.docx --number-sections=true --lof=true --toc=true --include-before-body=cover.docx
--include-before-body 选项:
-B FILE, --include-before-body=FILE|URL
Include contents of FILE, verbatim, at the beginning of the document body (e.g. after the <body> tag in HTML, or the \begin{document} command in LaTeX). This can be used to include navigation bars or banners in HTML documents.
This option can be used repeatedly to include multiple files. They will be included in the order specified. Implies --standalone. Note that if the output format is odt,
this file must be in OpenDocument XML format suitable for insertion into the body of the document, and if the output is docx, this file must be in appropriate OpenXML format.
但是当我尝试传递一个简单的 cover.docx 文件时,它会失败并出现以下错误
UTF-8 decoding error in cover.docx at byte offset 10 (b2). The input must be a UTF-8 encoded text
我尝试生成 cover.doc、cover.docx(严格的 office XML)、cover.docx,但仍然不起作用。
在目录之前添加一个部分是正确的方法吗?如果是,我做错了什么?
大多数变量只有在具有相应变量的 pandoc 模板时才有效。但 docx 输出不使用模板,而是使用reference-doc。
但是
include-before-body
您应该能够提供一个带有 XML 片段的文件(pandoc 将在此 XML 文件中插入)。这意味着您可以使用任何纯文本编辑器打开该文件。请确保不要提供.docx
文件本身(它基本上是一个.zip
文件)。但是,如果您不需要特殊格式,编写类似于此过滤器的pandoc lua 过滤器可能会更容易。