diff options
Diffstat (limited to 'paper/lua-filters/pagebreak')
-rw-r--r-- | paper/lua-filters/pagebreak/Makefile | 4 | ||||
-rw-r--r-- | paper/lua-filters/pagebreak/README.md | 68 | ||||
-rw-r--r-- | paper/lua-filters/pagebreak/expected.html | 6 | ||||
-rw-r--r-- | paper/lua-filters/pagebreak/pagebreak.lua | 97 | ||||
-rw-r--r-- | paper/lua-filters/pagebreak/sample.md | 14 |
5 files changed, 0 insertions, 189 deletions
diff --git a/paper/lua-filters/pagebreak/Makefile b/paper/lua-filters/pagebreak/Makefile deleted file mode 100644 index c8786b0..0000000 --- a/paper/lua-filters/pagebreak/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -test: - @pandoc --lua-filter=pagebreak.lua sample.md | diff -u expected.html - - -.PHONY: test diff --git a/paper/lua-filters/pagebreak/README.md b/paper/lua-filters/pagebreak/README.md deleted file mode 100644 index b9a5e04..0000000 --- a/paper/lua-filters/pagebreak/README.md +++ /dev/null @@ -1,68 +0,0 @@ -pagebreak -========= - -This filter converts paragraps containing only the LaTeX -`\newpage` or `\pagebreak` command into appropriate pagebreak -markup for other formats. The command must be the only contents -of a raw TeX block in order to be recognized. I.e., for Markdown -the following is sufficient: - - Paragraph before page break - - \newpage - - Paragraph after page break - - -Usage ------ - -Fully supported output formats are: - -- Docx, -- LaTeX, -- HTML, and -- EPUB. - -ODT is supported, but requires additional settings in the -reference document (see below). - -In all other formats, the page break is represented using the -form feed character. - - -### Usage with HTML -If you want to use an HTML class rather than an inline style set -the value of the metadata key `newpage_html_class` or the -environment variable `PANDOC_NEWPAGE_HTML_CLASS` (the metadata -'wins' if both are defined) to the name of the class and use CSS -like this: - - @media all { - .page-break { display: none; } - } - @media print { - .page-break { display: block; page-break-after: always; } - } - - -### Usage with ODT - -To use with ODT you must create a reference ODT with a named -paragraph style called `Pagebreak` (or whatever you set the -metadata field `newpage_odt_style` or the environment variable -`PANDOC_NEWPAGE_ODT_STYLE` to) and define it as having no extra -space before or after but set it to have a pagebreak after it -<https://help.libreoffice.org/Writer/Text_Flow>. - -(There will be an empty dummy paragraph, which means some extra -vertical space, and you probably want that space to go at the -bottom of the page before the break rather than at the top of -the page after the break!) - - -Alternative syntax ------------------- - -The form feed character as the only element in a paragraph is -supported as an alternative to the LaTeX syntax described above. diff --git a/paper/lua-filters/pagebreak/expected.html b/paper/lua-filters/pagebreak/expected.html deleted file mode 100644 index 7998826..0000000 --- a/paper/lua-filters/pagebreak/expected.html +++ /dev/null @@ -1,6 +0,0 @@ -<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec hendrerit tempor tellus. Donec pretium posuere tellus.</p> -<div style="page-break-after: always;"></div> -<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla posuere. Donec vitae dolor.</p> -<div style="page-break-after: always;"></div> -<p>Pellentesque dapibus suscipit ligula. Donec posuere augue in quam. Suspendisse potenti.</p> -<p>Final paragraph without a preceding pagebreak.</p> diff --git a/paper/lua-filters/pagebreak/pagebreak.lua b/paper/lua-filters/pagebreak/pagebreak.lua deleted file mode 100644 index 4c00698..0000000 --- a/paper/lua-filters/pagebreak/pagebreak.lua +++ /dev/null @@ -1,97 +0,0 @@ ---[[ -pagebreak – convert raw LaTeX page breaks to other formats - -Copyright © 2017-2019 Benct Philip Jonsson, Albert Krewinkel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -]] -local stringify_orig = (require 'pandoc.utils').stringify - -local function stringify(x) - return type(x) == 'string' and x or stringify_orig(x) -end - ---- configs – these are populated in the Meta filter. -local pagebreak = { - epub = '<p style="page-break-after: always;"> </p>', - html = '<div style="page-break-after: always;"></div>', - latex = '\\newpage{}', - ooxml = '<w:p><w:r><w:br w:type="page"/></w:r></w:p>', -} - -local function pagebreaks_from_config (meta) - local html_class = - (meta.newpage_html_class and stringify(meta.newpage_html_class)) - or os.getenv 'PANDOC_NEWPAGE_HTML_CLASS' - if html_class and html_class ~= '' then - pagebreak.html = string.format('<div class="%s"></div>', html_class) - end - - local odt_style = - (meta.newpage_odt_style and stringify(meta.newpage_odt_style)) - or os.getenv 'PANDOC_NEWPAGE_ODT_STYLE' - if odt_style and odt_style ~= '' then - pagebreak.odt = string.format('<text:p text:style-name="%s"/>', odt_style) - end -end - ---- Return a block element causing a page break in the given format. -local function newpage(format) - if format == 'docx' then - return pandoc.RawBlock('openxml', pagebreak.ooxml) - elseif format:match 'latex' then - return pandoc.RawBlock('tex', pagebreak.latex) - elseif format:match 'html.*' then - return pandoc.RawBlock('html', pagebreak.html) - elseif format:match 'epub' then - return pandoc.RawBlock('html', pagebreak.epub) - else - -- fall back to insert a form feed character - return pandoc.Para{pandoc.Str '\f'} - end -end - -local function is_newpage_command(command) - return command:match '^\\newpage%{?%}?$' - or command:match '^\\pagebreak%{?%}?$' -end - --- Filter function called on each RawBlock element. -function RawBlock (el) - -- Don't do anything if the output is TeX - if FORMAT:match 'tex$' then - return nil - end - -- check that the block is TeX or LaTeX and contains only - -- \newpage or \pagebreak. - if el.format:match 'tex' and is_newpage_command(el.text) then - -- use format-specific pagebreak marker. FORMAT is set by pandoc to - -- the targeted output format. - return newpage(FORMAT) - end - -- otherwise, leave the block unchanged - return nil -end - --- Turning paragraphs which contain nothing but a form feed --- characters into line breaks. -function Para (el) - if #el.content == 1 and el.content[1].text == '\f' then - return newpage(FORMAT) - end -end - -return { - {Meta = pagebreaks_from_config}, - {RawBlock = RawBlock, Para = Para} -} diff --git a/paper/lua-filters/pagebreak/sample.md b/paper/lua-filters/pagebreak/sample.md deleted file mode 100644 index dc49ce1..0000000 --- a/paper/lua-filters/pagebreak/sample.md +++ /dev/null @@ -1,14 +0,0 @@ -Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec -hendrerit tempor tellus. Donec pretium posuere tellus. - -\newpage - -Cum sociis natoque penatibus et magnis dis parturient montes, -nascetur ridiculus mus. Nulla posuere. Donec vitae dolor. - - - -Pellentesque dapibus suscipit ligula. Donec posuere augue in -quam. Suspendisse potenti. - -Final paragraph without a preceding pagebreak. |