Update paragraph using lua filter

Viewed 285

I'm trying to improve the filtering code I have for filtering input.

The input I have looks like this:

<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>

I use a filter like this in order to replace words "Pagebreak" with actual docx pagebreak XML piece:

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}
}

I control the input HTML, and would like to simplify it by removing <p style="display: none">Pagebreak</p> in favor of an attribute on regular paragraph. What I'd like to have is this:

<html>
  <body>
    <p>Page 1</p>
    <p class="pageBreak">Page 2</p>
    <p class="pageBreak">Page 3</p>
  </body>
</html>

What lua code should I write to achieve this?

From the "Creating a handout from a paper" example I see that it's possible to inspect the classes of incoming elements. But how do I modify the existing paragraph to have a page break in it?

1 Answers
Related