Blame Raw
permissionBRICK · 9f53616a · · 39 lines (1.2 KB)
1 contributor
1-- pagebreak.lua
2-- Converts explicit page break markers into format-specific page breaks.
3
4local DOCX_PAGEBREAK = [[
5<w:p>
6 <w:r>
7 <w:br w:type="page"/>
8 </w:r>
9</w:p>
10]]
11
12local HTML_PAGEBREAK = '<div style="page-break-before: always;"></div>'
13
14local 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 )
19end
20
21function 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
29end
30
31function 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
39end