From 38a23550bb87e8c30002526f153d0942772c36da Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 15 Apr 2026 22:25:11 +0200 Subject: [PATCH] Typst writer: newline after `#set text` directive. This ensures that blocks such as lists are parsed correctly after a `set text`. Closes #11583. --- src/Text/Pandoc/Writers/Typst.hs | 9 +++++---- test/command/10965.md | 9 ++++++--- test/command/11583.md | 16 ++++++++++++++++ test/command/typst-property-output.md | 15 +++++++++------ 4 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 test/command/11583.md diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index 3acefc15f..1aa59767d 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -164,10 +164,10 @@ toTypstTextElement typstTextAttrs content = "#text" <> toTypstPropsListParens ty toTypstSetText :: [(Text, Text)] -> Doc Text toTypstSetText [] = "" -toTypstSetText typstTextAttrs = "set text" <> parens (toTypstPropsListSep typstTextAttrs) <> "; " +toTypstSetText typstTextAttrs = "set text" <> parens (toTypstPropsListSep typstTextAttrs) <> ";" toTypstPoundSetText :: [(Text, Text)] -> Doc Text -toTypstPoundSetText [] = "" +toTypstPoundSetText [] = mempty toTypstPoundSetText typstTextAttrs = "#" <> toTypstSetText typstTextAttrs toTypstBracesSetText :: [(Text, Text)] -> Doc Text -> Doc Text @@ -313,7 +313,7 @@ blockToTypst block = ColSpan n -> [ "colspan: " <> tshow n ]) ++ map formatTypstProp typstAttrs2 cellContents <- blocksToTypst bs - let contents2 = brackets (toTypstPoundSetText typstTextAttrs <> cellContents) + let contents2 = brackets (toTypstPoundSetText typstTextAttrs $$ cellContents) pure $ if null cellattrs then contents2 else "table.cell" <> @@ -395,7 +395,8 @@ blockToTypst block = let allTypstTextAttrs = typstTextAttrs ++ langAttrs contents <- blocksToTypst blocks return $ "#block" <> toTypstPropsListParens typstAttrs <> "[" - $$ toTypstPoundSetText allTypstTextAttrs <> contents + $$ toTypstPoundSetText allTypstTextAttrs + $$ contents $$ ("]" <+> lab) defListItemToTypst :: PandocMonad m => ([Inline], [[Block]]) -> TW m (Doc Text) diff --git a/test/command/10965.md b/test/command/10965.md index 565723278..7732c3439 100644 --- a/test/command/10965.md +++ b/test/command/10965.md @@ -5,7 +5,8 @@ This text should be in English. ::: ^D #block[ -#set text(lang: "en"); This text should be in English. +#set text(lang: "en"); +This text should be in English. ] ``` @@ -17,7 +18,8 @@ Ce texte devrait être en français. ::: ^D #block[ -#set text(lang: "fr"); Ce texte devrait être en français. +#set text(lang: "fr"); +Ce texte devrait être en français. ] ``` @@ -29,7 +31,8 @@ Dieser Text sollte auf Deutsch sein. ::: ^D #block[ -#set text(lang: "de"); Dieser Text sollte auf Deutsch sein. +#set text(lang: "de"); +Dieser Text sollte auf Deutsch sein. ] ``` diff --git a/test/command/11583.md b/test/command/11583.md new file mode 100644 index 000000000..ad92c202b --- /dev/null +++ b/test/command/11583.md @@ -0,0 +1,16 @@ +``` +% pandoc -t typst +::: {lang=en} +1. item +2. item +3. item +::: +^D +#block[ +#set text(lang: "en"); ++ item ++ item ++ item + +] +``` diff --git a/test/command/typst-property-output.md b/test/command/typst-property-output.md index e809e19f3..b20b65969 100644 --- a/test/command/typst-property-output.md +++ b/test/command/typst-property-output.md @@ -26,7 +26,8 @@ foo
foo
^D #block[ -#set text(fill: purple); foo +#set text(fill: purple); +foo ] ``` @@ -63,7 +64,7 @@ foo ^D #figure( - align(center)[#set text(fill: orange); #table( + align(center)[#set text(fill: orange);#table( columns: 2, align: (auto,auto,), [A], [B], @@ -98,7 +99,8 @@ foo align(center)[#table( columns: 2, align: (auto,auto,), - [A], [#set text(fill: fuchsia); B], + [A], [#set text(fill: fuchsia); + B], )] , kind: table ) @@ -114,7 +116,8 @@ foo align(center)[#table( columns: 2, align: (auto,center,), - [A], table.cell(align: center)[#set text(fill: maroon); B], + [A], table.cell(align: center)[#set text(fill: maroon); + B], )] , kind: table ) @@ -169,7 +172,7 @@ foo ^D Paragraph before. -#{set text(size: 3em); table( +#{set text(size: 3em);table( columns: 3, align: (auto,auto,auto,), [A], [B], [C], @@ -195,7 +198,7 @@ Paragraph after. Paragraph before. #figure( - align(center)[#set text(size: 3em); #table( + align(center)[#set text(size: 3em);#table( columns: 3, align: (auto,auto,auto,), [A], [B], [C],