Skip to content

Commit

Permalink
pagebreak: add support for Typst
Browse files Browse the repository at this point in the history
  • Loading branch information
s22h authored and tarleb committed Sep 27, 2023
1 parent 0e76592 commit 3f92f93
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FILTER_FILE := $(wildcard *.lua)
DIFF ?= diff
PANDOC ?= pandoc

test: test-adoc test-html test-ms test-no-form-feed.html
test: test-adoc test-html test-ms test-typst test-no-form-feed.html

test-%: $(FILTER_FILE) test/input.md test/test-%.yaml
@$(PANDOC) --defaults test/test-$*.yaml | \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Fully supported output formats are:
- Docx,
- EPUB,
- groff ms,
- Typst
- HTML, and
- LaTeX.

Expand Down
5 changes: 4 additions & 1 deletion pagebreak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ local default_pagebreaks = {
latex = '\\newpage{}',
ms = '.bp',
ooxml = '<w:p><w:r><w:br w:type="page"/></w:r></w:p>',
odt = '<text:p text:style-name="Pagebreak"/>'
odt = '<text:p text:style-name="Pagebreak"/>',
typst = '#pagebreak()\n\n'
}

local function pagebreak_from_config (config)
Expand Down Expand Up @@ -66,6 +67,8 @@ local function newpage(format, pagebreak)
return pandoc.RawBlock('ms', pagebreak.ms)
elseif format:match 'odt' then
return pandoc.RawBlock('opendocument', pagebreak.odt)
elseif format:match 'typst' then
return pandoc.RawBlock('typst', pagebreak.typst)
else
-- fall back to insert a form feed character
return pandoc.Para{pandoc.Str '\f'}
Expand Down
14 changes: 14 additions & 0 deletions test/expected.typst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
hendrerit tempor tellus. Donec pretium posuere tellus.

#pagebreak()

Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus. Nulla posuere. Donec vitae dolor.

#pagebreak()

Pellentesque dapibus suscipit ligula. Donec posuere augue in quam.
Suspendisse potenti.

Final paragraph without a preceding pagebreak.
9 changes: 9 additions & 0 deletions test/test-typst.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
input-files: [test/input.md]
to: typst
filters:
- pagebreak.lua

metadata:
pagebreak:
break-on:
form-feed: true

0 comments on commit 3f92f93

Please sign in to comment.