Skip to content

Commit

Permalink
Add typst writer.
Browse files Browse the repository at this point in the history
See #8713.

Still needed:

- PDF-via-typst support
- fuller table support
  • Loading branch information
jgm committed Mar 26, 2023
1 parent d8ec5c4 commit 31bf02b
Show file tree
Hide file tree
Showing 11 changed files with 1,254 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- '*'
- '!rc/*'
- '!typst-writer'
paths-ignore:
- 'doc/*.md'
- 'MANUAL.txt'
Expand Down
2 changes: 2 additions & 0 deletions MANUAL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ header when requesting a document from a URL:
- `revealjs` ([reveal.js] HTML5 + JavaScript slide show)
- `s5` ([S5] HTML and JavaScript slide show)
- `tei` ([TEI Simple])
- `typst` ([typst])
- `xwiki` ([XWiki markup])
- `zimwiki` ([ZimWiki markup])
- the path of a custom Lua writer, see [Custom readers and writers] below
Expand Down Expand Up @@ -515,6 +516,7 @@ header when requesting a document from a URL:
[BibLaTeX]: https://ctan.org/pkg/biblatex
[Markua]: https://leanpub.com/markua/read
[EndNote XML bibliography]: https://support.clarivate.com/Endnote/s/article/EndNote-XML-Document-Type-Definition
[typst]: https://typst.app

## Reader options {.options}

Expand Down
93 changes: 93 additions & 0 deletions data/templates/default.typst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#set page(
$if(papersize)$
paper: "$papersize$",
$endif$
numbering: "1"
)
#set par(justify: true)
#set text(
$if(lang)$
lang: "$lang$",
$endif$
$if(mainfont)$
font: "$mainfont$",
$endif$
$if(fontsize)$
size: $fontsize$,
$endif$
)
#set heading(
$if(numbering)$
numbering: "$numbering$"
$endif$
)

#align(center)[#block(inset: 2em)[
#text(weight: "bold", size: 18pt)[$title$] \
$for(author)$
$author$ \
$endfor$
$if(date)$
$date$
$endif$
]]

#let definition(term, ..defs) = [
#strong(term) \
#(defs.pos().join("\n"))
]

#let blockquote(body) = [
#set text( size: 0.92em )
#block(inset: (left: 1.5em, top: 0.2em, bottom: 0.2em))[#body]
]

#let horizontalrule = [
#line(start: (25%,0%), end: (75%,0%))
]

#let endnote(num, contents) = [
#stack(dir: ltr, spacing: 3pt, super[#num], contents)
]

$if(columns)$
#show: doc => columns($columns$, doc)
$endif$

$for(header-includes)$
$header-includes$

$endfor$
$for(include-before)$
$include-before$

$endfor$
$if(toc)$
#outline(
title: auto,
depth: none
);
$endif$

$body$

#v(1em)
#block[
#horizontalrule
#set text(size: .88em)
#v(3pt) // otherwise first note marker is swallowed, bug?

$notes$
]
$if(bibliographystyle)$

#set bibliography(style: "$bibliographystyle$")
$endif$
$for(bibliography)$

#bibliography("$bibliography$")
$endfor$
$for(include-after)$

$include-after$
$endfor$
5 changes: 5 additions & 0 deletions pandoc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ description: Pandoc is a Haskell library for converting from one markup
- Documentation formats (GNU TexInfo, Haddock)
- Roff formats (man, ms)
- TeX formats (LaTeX, ConTeXt)
- Typst
- XML formats (DocBook 4 and 5, JATS, TEI Simple, OpenDocument)
- Outline formats (OPML)
- Bibliography formats (BibTeX, BibLaTeX, CSL JSON, CSL YAML,
Expand Down Expand Up @@ -94,6 +95,7 @@ data-files:
data/templates/article.jats_publishing
data/templates/affiliations.jats
data/templates/default.markua
data/templates/default.typst
-- translations
data/translations/*.yaml
-- entities
Expand Down Expand Up @@ -315,6 +317,7 @@ extra-source-files:
test/tables.asciidoctor
test/tables.haddock
test/tables.texinfo
test/tables.typst
test/tables.rst
test/tables.rtf
test/tables.txt
Expand Down Expand Up @@ -345,6 +348,7 @@ extra-source-files:
test/writer.plain
test/writer.mediawiki
test/writer.textile
test/writer.typst
test/writer.opendocument
test/writer.org
test/writer.asciidoc
Expand Down Expand Up @@ -589,6 +593,7 @@ library
Text.Pandoc.Writers.Jira,
Text.Pandoc.Writers.LaTeX,
Text.Pandoc.Writers.ConTeXt,
Text.Pandoc.Writers.Typst,
Text.Pandoc.Writers.OpenDocument,
Text.Pandoc.Writers.Texinfo,
Text.Pandoc.Writers.Man,
Expand Down
2 changes: 2 additions & 0 deletions src/Text/Pandoc/Extensions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ getDefaultExtensions "jats_articleauthoring" = getDefaultExtensions "jats"
getDefaultExtensions "opml" = pandocExtensions -- affects notes
getDefaultExtensions "markua" = extensionsFromList
[]
getDefaultExtensions "typst" = extensionsFromList [Ext_citations]
getDefaultExtensions _ = extensionsFromList
[Ext_auto_identifiers]

Expand Down Expand Up @@ -644,4 +645,5 @@ getAllExtensions f = universalExtensions <> getAll f
getAll "mediawiki" = autoIdExtensions <>
extensionsFromList
[ Ext_smart ]
getAll "typst" = extensionsFromList [Ext_citations]
getAll _ = mempty
1 change: 1 addition & 0 deletions src/Text/Pandoc/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ formatFromFilePath x =
".textile" -> defFlavor "textile"
".tsv" -> defFlavor "tsv"
".txt" -> defFlavor "markdown"
".typ" -> defFlavor "typst"
".wiki" -> defFlavor "mediawiki"
".xhtml" -> defFlavor "html"
['.',y] | y `elem` ['1'..'9'] -> defFlavor "man"
Expand Down
3 changes: 3 additions & 0 deletions src/Text/Pandoc/Writers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module Text.Pandoc.Writers
, writeTEI
, writeTexinfo
, writeTextile
, writeTypst
, writeXWiki
, writeZimWiki
, getWriter
Expand Down Expand Up @@ -121,6 +122,7 @@ import Text.Pandoc.Writers.RTF
import Text.Pandoc.Writers.TEI
import Text.Pandoc.Writers.Texinfo
import Text.Pandoc.Writers.Textile
import Text.Pandoc.Writers.Typst
import Text.Pandoc.Writers.XWiki
import Text.Pandoc.Writers.ZimWiki

Expand Down Expand Up @@ -177,6 +179,7 @@ writers = [
,("xwiki" , TextWriter writeXWiki)
,("zimwiki" , TextWriter writeZimWiki)
,("textile" , TextWriter writeTextile)
,("typst" , TextWriter writeTypst)
,("rtf" , TextWriter writeRTF)
,("org" , TextWriter writeOrg)
,("asciidoc" , TextWriter writeAsciiDoc)
Expand Down
Loading

0 comments on commit 31bf02b

Please sign in to comment.