我有一个像这样的Markdown列表:
* 问题 A
- 答案 1
- 答案 2
- 答案 3
当我使用Pandoc将Markdown文档转换为docx时,我需要确保所有答案(1-3)与问题A出现在同一页上。我该怎么做?
我有一个像这样的Markdown列表:
* 问题 A
- 答案 1
- 答案 2
- 答案 3
当我使用Pandoc将Markdown文档转换为docx时,我需要确保所有答案(1-3)与问题A出现在同一页上。我该怎么做?
使用自定义样式在您的Markdown中,然后在自定义docx模板中定义这些样式。
值得注意的是,Pandoc的文档(强调添加):
因为pandoc对文档的中间表示不如它转换之间的许多格式表达力强,所以不应期望每种格式和其他格式之间都有完美的转换。 Pandoc试图保留文档的结构元素,但不保留格式细节...
当然,Markdown没有“页面”或“分页符”的概念,因此这不是Pandoc默认处理的内容。但是,Pandoc知道docx样式。如文档所解释的那样:
如果您不想手动定义样式,但希望它自动应用于每个列表(或者可能是每个遵循特定模式的列表),您可以定义一个自定义过滤器,将样式应用于文档中的每个匹配元素。By default, pandoc’s docx output applies a predefined set of styles for blocks such as paragraphs and block quotes, and uses largely default formatting (italics, bold) for inlines. This will work for most purposes, especially alongside a
reference.docx
file. However, if you need to apply your own styles to blocks, or match a preexisting set of styles, pandoc allows you to define custom styles for blocks and text usingdivs
andspans
, respectively.If you define a
div
orspan
with the attributecustom-style
, pandoc will apply your specified style to the contained elements. So, for example using thebracketed_spans
syntax,
[Get out]{custom-style="Emphatically"}, he said.
would produce a docx file with “Get out” styled with character style
Emphatically
. Similarly, using thefenced_divs
syntax,Dickinson starts the poem simply:
::: {custom-style="Poetry"} | A Bird came down the Walk--- | He did not know I saw--- :::
would style the two contained lines with the
Poetry
paragraph style.If the styles are not yet in your
reference.docx
, they will be defined in the output file as inheriting fromnormal
text. If they are already defined, pandoc will not alter the definition.
--reference-doc
选项的文档所解释的那样:--reference-doc=custom-reference.docx
,您的自定义样式定义将包含在生成的docx文件中。只要您还正确标识了Markdown文档中哪些元素获取哪些样式,您应该获得一个列表,该列表不会在跨页断开时被打破,只要整个列表适合一页即可。