【问题标题】:Update paragraph using lua filter使用 lua 过滤器更新段落
【发布时间】: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,并希望通过删除 &lt;p style="display: none"&gt;Pagebreak&lt;/p&gt; 以支持常规段落的属性来简化它。我想要的是这样的:

<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”示例中,我看到可以检查传入元素的类。但是如何修改现有段落以在其中添加分页符?

【问题讨论】:

    标签: lua pandoc


    【解决方案1】:

    不幸的是,pandoc 的文档模型目前为doesn't support attributes on paragraphs。但是,您可以改用div

    <div class="pageBreak">Page 3</div>
    

    我看到你已经找到open issue about page breaks

    【讨论】:

      猜你喜欢
      • 2022-08-18
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 2017-07-26
      相关资源
      最近更新 更多