【发布时间】:2020-07-02 20:37:25
【问题描述】:
我正在尝试改进用于过滤输入的过滤代码。
我的输入如下所示:
<html>
<body>
<p>Page 1</p>
<p style="display: none">Pagebreak</p>
<p>Page 2</p>
<p style="display: none">Pagebreak</p>
<p>Page 3</p>
</body>
</html>
我使用这样的过滤器来将单词“Pagebreak”替换为实际的 docx pagebreak XML 片段:
function Para (el)
-- Turning paragraphs which contain nothing but a Pagebreak word
-- into line breaks.
if #el.content == 1 and el.content[1].text == "Pagebreak" then
return pandoc.RawBlock('openxml', '<w:p><w:r><w:br w:type="page"/></w:r></w:p>')
end
end
return {
{Para = Para}
}
我控制输入 HTML,并希望通过删除 <p style="display: none">Pagebreak</p> 以支持常规段落的属性来简化它。我想要的是这样的:
<html>
<body>
<p>Page 1</p>
<p class="pageBreak">Page 2</p>
<p class="pageBreak">Page 3</p>
</body>
</html>
我应该编写什么 lua 代码来实现这一点?
从“Creating a handout from a paper”示例中,我看到可以检查传入元素的类。但是如何修改现有段落以在其中添加分页符?
【问题讨论】: