aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGordon Woodhull <[email protected]>2025-01-24 13:48:03 -0500
committerGitHub <[email protected]>2025-01-24 10:48:03 -0800
commit220dde406b6ed835b8ac7a267807bbeea53a190d (patch)
tree14073f92cc8d4127568f8007a534dc367e96a2ec /src
parentb95645b0a0c26afb22e51d1e220e79a0c47a927c (diff)
brace tables with typst:no-figure and typst:text attributes (#10563)
The combination of #9648 Typst property output and #9778 `typst:no-figure` can cause fonts to spill out of tables. This is because setting Typst text properties across a table requires `set text(...)` outside the 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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Typst.hs20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs
index 562b86f79..c935825f4 100644
--- a/src/Text/Pandoc/Writers/Typst.hs
+++ b/src/Text/Pandoc/Writers/Typst.hs
@@ -131,7 +131,15 @@ toTypstTextElement typstTextAttrs content = "#text" <> toTypstPropsListParens ty
toTypstSetText :: [(Text, Text)] -> Doc Text
toTypstSetText [] = ""
-toTypstSetText typstTextAttrs = "#set text" <> parens (toTypstPropsListSep typstTextAttrs) <> "; " -- newline?
+toTypstSetText typstTextAttrs = "set text" <> parens (toTypstPropsListSep typstTextAttrs) <> "; "
+
+toTypstPoundSetText :: [(Text, Text)] -> Doc Text
+toTypstPoundSetText [] = ""
+toTypstPoundSetText typstTextAttrs = "#" <> toTypstSetText typstTextAttrs
+
+toTypstBracesSetText :: [(Text, Text)] -> Doc Text -> Doc Text
+toTypstBracesSetText [] x = "#" <> x
+toTypstBracesSetText typstTextAttrs x = "#" <> braces (toTypstSetText typstTextAttrs <> x)
blocksToTypst :: PandocMonad m => [Block] -> TW m (Doc Text)
blocksToTypst blocks = vcat <$> mapM blockToTypst blocks
@@ -259,7 +267,7 @@ blockToTypst block =
ColSpan n -> [ "colspan: " <> tshow n ]) ++
map formatTypstProp typstAttrs2
cellContents <- blocksToTypst bs
- let contents2 = brackets (toTypstSetText typstTextAttrs <> cellContents)
+ let contents2 = brackets (toTypstPoundSetText typstTextAttrs <> cellContents)
pure $ if null cellattrs
then contents2
else "table.cell" <>
@@ -288,7 +296,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 <> ","
@@ -299,11 +307,11 @@ blockToTypst block =
)
$$ ")"
return $ if "typst:no-figure" `elem` tabclasses
- then table
+ then toTypstBracesSetText typstTextAttrs table
else "#figure("
$$
nest 2
- ("align(center)[" <> table <> "]"
+ ("align(center)[" <> toTypstPoundSetText typstTextAttrs <> "#" <> table <> "]"
$$ capt'
$$ typstFigureKind
$$ ")")
@@ -332,7 +340,7 @@ blockToTypst block =
let (typstAttrs,typstTextAttrs) = pickTypstAttrs kvs
contents <- blocksToTypst blocks
return $ "#block" <> toTypstPropsListParens typstAttrs <> "["
- $$ toTypstSetText typstTextAttrs <> contents
+ $$ toTypstPoundSetText typstTextAttrs <> contents
$$ ("]" <+> lab)
defListItemToTypst :: PandocMonad m => ([Inline], [[Block]]) -> TW m (Doc Text)