Typst writer: newline after #set text directive.

This ensures that blocks such as lists are parsed correctly
after a `set text`.

Closes #11583.
This commit is contained in:
John MacFarlane
2026-04-15 22:25:11 +02:00
parent 5caad90fc4
commit 38a23550bb
4 changed files with 36 additions and 13 deletions
+5 -4
View File
@@ -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)
+6 -3
View File
@@ -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.
]
```
+16
View File
@@ -0,0 +1,16 @@
```
% pandoc -t typst
::: {lang=en}
1. item
2. item
3. item
:::
^D
#block[
#set text(lang: "en");
+ item
+ item
+ item
]
```
+9 -6
View File
@@ -26,7 +26,8 @@ foo
<div typst:text:fill="purple">foo</div>
^D
#block[
#set text(fill: purple); foo
#set text(fill: purple);
foo
]
```
@@ -63,7 +64,7 @@ foo
</table>
^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],