| 1 | -- pagebreak.lua |
| 2 | -- Converts explicit page break markers into format-specific page breaks. |
| 3 | |
| 4 | local DOCX_PAGEBREAK = [[ |
| 5 | <w:p> |
| 6 | <w:r> |
| 7 | <w:br w:type="page"/> |
| 8 | </w:r> |
| 9 | </w:p> |
| 10 | ]] |
| 11 | |
| 12 | local HTML_PAGEBREAK = '<div style="page-break-before: always;"></div>' |
| 13 | |
| 14 | local function is_pagebreak(el) |
| 15 | return ( |
| 16 | (el.t == "RawBlock" and el.format == "tex" and (el.text == "\\newpage" or el.text == "\\pagebreak")) or |
| 17 | (el.t == "Para" and #el.content == 1 and el.content[1].t == "Str" and el.content[1].text == "\f") |
| 18 | ) |
| 19 | end |
| 20 | |
| 21 | function RawBlock(el) |
| 22 | if el.format == "tex" and (el.text == "\\newpage" or el.text == "\\pagebreak") then |
| 23 | if FORMAT == "docx" or FORMAT == "openxml" then |
| 24 | return pandoc.RawBlock("openxml", DOCX_PAGEBREAK) |
| 25 | elseif FORMAT == "epub" or FORMAT == "epub3" or FORMAT == "html" or FORMAT == "html5" then |
| 26 | return pandoc.RawBlock("html", HTML_PAGEBREAK) |
| 27 | end |
| 28 | end |
| 29 | end |
| 30 | |
| 31 | function Para(el) |
| 32 | if is_pagebreak(el) then |
| 33 | if FORMAT == "docx" or FORMAT == "openxml" then |
| 34 | return pandoc.RawBlock("openxml", DOCX_PAGEBREAK) |
| 35 | elseif FORMAT == "epub" or FORMAT == "epub3" or FORMAT == "html" or FORMAT == "html5" then |
| 36 | return pandoc.RawBlock("html", HTML_PAGEBREAK) |
| 37 | end |
| 38 | end |
| 39 | end |