Skip to content

Commit

Permalink
bracket tables with typst:no-figure and typst:text attributes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gordonwoodhull committed Jan 24, 2025
1 parent b95645b commit cc6d13e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Text/Pandoc/Writers/Typst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ toTypstSetText :: [(Text, Text)] -> Doc Text
toTypstSetText [] = ""
toTypstSetText typstTextAttrs = "#set text" <> parens (toTypstPropsListSep typstTextAttrs) <> "; " -- newline?

toTypstBracketsSetText :: [(Text, Text)] -> Doc Text -> Doc Text
toTypstBracketsSetText [] x = x
toTypstBracketsSetText typstTextAttrs x = "#" <> brackets (toTypstSetText typstTextAttrs <> x)

blocksToTypst :: PandocMonad m => [Block] -> TW m (Doc Text)
blocksToTypst blocks = vcat <$> mapM blockToTypst blocks

Expand Down Expand Up @@ -288,7 +292,7 @@ blockToTypst block =
header <- fromHead thead
footer <- fromFoot tfoot
body <- vcat <$> mapM fromTableBody tbodies
let table = toTypstSetText typstTextAttrs <> "#table("
let table = "#table("
$$ nest 2
( "columns: " <> columns <> ","
$$ "align: " <> alignarray <> ","
Expand All @@ -299,11 +303,11 @@ blockToTypst block =
)
$$ ")"
return $ if "typst:no-figure" `elem` tabclasses
then table
then toTypstBracketsSetText typstTextAttrs table
else "#figure("
$$
nest 2
("align(center)[" <> table <> "]"
("align(center)[" <> toTypstSetText typstTextAttrs <> table <> "]"
$$ capt'
$$ typstFigureKind
$$ ")")
Expand Down
78 changes: 78 additions & 0 deletions test/command/typst-property-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,81 @@ foo
, kind: table
)
```

```
% pandoc -f html -t typst
<p>Paragraph before.</p>
<table class="typst:no-figure" typst:text:size="3em">
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</table>
<p>Paragraph after.</p>
^D
Paragraph before.
#[#set text(size: 3em); #table(
columns: 3,
align: (auto,auto,auto,),
[A], [B], [C],
)]
Paragraph after.
```


```
% pandoc -f html -t typst
<p>Paragraph before.</p>
<table typst:text:size="3em">
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</table>
<p>Paragraph after.</p>
^D
Paragraph before.
#figure(
align(center)[#set text(size: 3em); #table(
columns: 3,
align: (auto,auto,auto,),
[A], [B], [C],
)]
, kind: table
)
Paragraph after.
```


```
% pandoc -f html -t typst
<p>Paragraph before.</p>
<table class="typst:no-figure">
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</table>
<p>Paragraph after.</p>
^D
Paragraph before.
#table(
columns: 3,
align: (auto,auto,auto,),
[A], [B], [C],
)
Paragraph after.
```

0 comments on commit cc6d13e

Please sign in to comment.