aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2024-03-18 10:13:51 -0700
committerJohn MacFarlane <[email protected]>2024-03-18 10:13:51 -0700
commitc5c7022ac537ff98f625432fe70bcd5b491d1d96 (patch)
tree2e870a103c9217f6d413d8bdc7ea15433f9474c6
parent602cf00dfcec10ddfad38beedcf1bd542fc1a688 (diff)
Typst writer: handle `unnumbered` on headings.
Closes #9585.
-rw-r--r--src/Text/Pandoc/Writers/Typst.hs13
-rw-r--r--test/command/9585.md11
2 files changed, 20 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs
index 7d061ed05..976980d20 100644
--- a/src/Text/Pandoc/Writers/Typst.hs
+++ b/src/Text/Pandoc/Writers/Typst.hs
@@ -97,13 +97,18 @@ blockToTypst block =
Header level (ident,cls,_) inlines -> do
contents <- inlinesToTypst inlines
let lab = toLabel FreestandingLabel ident
+ let headingAttrs =
+ ["outlined: false" | "unlisted" `elem` cls] ++
+ ["numbering: none" | "unnumbered" `elem` cls]
return $
- if "unlisted" `elem` cls
- then literal "#heading(outlined: false)" <> brackets contents <>
- cr <> lab
- else nowrap
+ if null headingAttrs
+ then nowrap
(literal (T.replicate level "=") <> space <> contents) <>
cr <> lab
+ else literal "#heading" <>
+ parens (literal (T.intercalate ", "
+ ("level: " <> tshow level : headingAttrs))) <>
+ brackets contents <> cr <> lab
RawBlock fmt str ->
case fmt of
Format "typst" -> return $ literal str
diff --git a/test/command/9585.md b/test/command/9585.md
new file mode 100644
index 000000000..a4d26ba5f
--- /dev/null
+++ b/test/command/9585.md
@@ -0,0 +1,11 @@
+```
+% pandoc -f native -t typst
+[ Header 2 ( "" , [] , [] ) [ Str "One" ]
+, Header 2 ( "" , [ "unnumbered", "unlisted" ] , [] ) [ Str "Two" ]
+, Header 2 ( "" , [] , [] ) [ Str "Three" ]
+]
+^D
+== One
+#heading(level: 2, outlined: false, numbering: none)[Two]
+== Three
+```