Skip to content

Commit cc6d13e

Browse files
bracket tables with typst:no-figure and typst:text attributes
The combination of #9648 Typst property output and #9778 `typst:no-figure` can cause fonts to spill out of tables, because setting Typst text properties across a table requires `#set text(...)` outside a table, and previously we were relying on the figure to provide a scope. This adds an extra `#[...]` when the table has class `typst:no-figure` and also has `typst:text:*` attributes.
1 parent b95645b commit cc6d13e

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed

src/Text/Pandoc/Writers/Typst.hs

+7-3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ toTypstSetText :: [(Text, Text)] -> Doc Text
133133
toTypstSetText [] = ""
134134
toTypstSetText typstTextAttrs = "#set text" <> parens (toTypstPropsListSep typstTextAttrs) <> "; " -- newline?
135135

136+
toTypstBracketsSetText :: [(Text, Text)] -> Doc Text -> Doc Text
137+
toTypstBracketsSetText [] x = x
138+
toTypstBracketsSetText typstTextAttrs x = "#" <> brackets (toTypstSetText typstTextAttrs <> x)
139+
136140
blocksToTypst :: PandocMonad m => [Block] -> TW m (Doc Text)
137141
blocksToTypst blocks = vcat <$> mapM blockToTypst blocks
138142

@@ -288,7 +292,7 @@ blockToTypst block =
288292
header <- fromHead thead
289293
footer <- fromFoot tfoot
290294
body <- vcat <$> mapM fromTableBody tbodies
291-
let table = toTypstSetText typstTextAttrs <> "#table("
295+
let table = "#table("
292296
$$ nest 2
293297
( "columns: " <> columns <> ","
294298
$$ "align: " <> alignarray <> ","
@@ -299,11 +303,11 @@ blockToTypst block =
299303
)
300304
$$ ")"
301305
return $ if "typst:no-figure" `elem` tabclasses
302-
then table
306+
then toTypstBracketsSetText typstTextAttrs table
303307
else "#figure("
304308
$$
305309
nest 2
306-
("align(center)[" <> table <> "]"
310+
("align(center)[" <> toTypstSetText typstTextAttrs <> table <> "]"
307311
$$ capt'
308312
$$ typstFigureKind
309313
$$ ")")

test/command/typst-property-output.md

+78
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,81 @@ foo
152152
, kind: table
153153
)
154154
```
155+
156+
```
157+
% pandoc -f html -t typst
158+
<p>Paragraph before.</p>
159+
160+
<table class="typst:no-figure" typst:text:size="3em">
161+
<tr>
162+
<td>A</td>
163+
<td>B</td>
164+
<td>C</td>
165+
</tr>
166+
</table>
167+
168+
<p>Paragraph after.</p>
169+
^D
170+
Paragraph before.
171+
172+
#[#set text(size: 3em); #table(
173+
columns: 3,
174+
align: (auto,auto,auto,),
175+
[A], [B], [C],
176+
)]
177+
Paragraph after.
178+
```
179+
180+
181+
```
182+
% pandoc -f html -t typst
183+
<p>Paragraph before.</p>
184+
185+
<table typst:text:size="3em">
186+
<tr>
187+
<td>A</td>
188+
<td>B</td>
189+
<td>C</td>
190+
</tr>
191+
</table>
192+
193+
<p>Paragraph after.</p>
194+
^D
195+
Paragraph before.
196+
197+
#figure(
198+
align(center)[#set text(size: 3em); #table(
199+
columns: 3,
200+
align: (auto,auto,auto,),
201+
[A], [B], [C],
202+
)]
203+
, kind: table
204+
)
205+
206+
Paragraph after.
207+
```
208+
209+
210+
```
211+
% pandoc -f html -t typst
212+
<p>Paragraph before.</p>
213+
214+
<table class="typst:no-figure">
215+
<tr>
216+
<td>A</td>
217+
<td>B</td>
218+
<td>C</td>
219+
</tr>
220+
</table>
221+
222+
<p>Paragraph after.</p>
223+
^D
224+
Paragraph before.
225+
226+
#table(
227+
columns: 3,
228+
align: (auto,auto,auto,),
229+
[A], [B], [C],
230+
)
231+
Paragraph after.
232+
```

0 commit comments

Comments
 (0)