diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2024-03-14 10:16:51 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2024-03-14 10:16:51 -0700 |
| commit | 876bd497868c4511e4463005062350c52324d22c (patch) | |
| tree | c6feb1b5a9aa96e048f087ea2edb676acfb540f5 /src/Text | |
| parent | b2b04a2f1c787344d09740498a1ee0319d657b88 (diff) | |
Typst writer: add 'kind' parameter to figures.
This helps to distinguish tables from other figures for
purposes of labeling and numbering.
Closes #9574.
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index c9df66f77..515f0bee7 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -175,26 +175,38 @@ blockToTypst block = formatalign AlignCenter = "center," formatalign AlignDefault = "auto," let alignarray = parens $ mconcat $ map formatalign aligns - return $ "#figure(" $$ - "align(center)[#table(" - $$ nest 2 - ( "columns: " <> text (show numcols) <> "," -- auto - $$ "align: (col, row) => " <> alignarray <> ".at(col)," - $$ "inset: 6pt" <> "," - $$ hsep (map ((<>",") . brackets) headers') - $$ vcat (map (\x -> brackets x <> ",") (concat rows')) - ) - $$ ")]" - $$ capt' - $$ ")" + return $ + "#figure(" + $$ + nest 2 + ("align(center)[#table(" + $$ nest 2 + ( "columns: " <> text (show numcols) <> "," -- auto + $$ "align: (col, row) => " <> alignarray <> ".at(col)," + $$ "inset: 6pt" <> "," + $$ hsep (map ((<>",") . brackets) headers') + $$ vcat (map (\x -> brackets x <> ",") (concat rows')) + ) + $$ ")]" + $$ capt' + $$ ", kind: table" + $$ ")") $$ lab $$ blankline Figure (ident,_,_) (Caption _mbshort capt) blocks -> do caption <- blocksToTypst capt contents <- blocksToTypst blocks let lab = toLabel FreestandingLabel ident - return $ "#figure(" <> nest 2 (brackets contents <> "," <> cr <> - ("caption: [" $$ nest 2 caption $$ "]")) + let kind = case blocks of + Table{}:_ -> "table" + CodeBlock{}:_ -> "code" + _ -> "auto" + return $ "#figure(" <> nest 2 ((brackets contents <> ",") + $$ + ("caption: [" $$ nest 2 caption $$ "],") + $$ + "kind: " <> literal kind + ) $$ ")" $$ lab $$ blankline Div (ident,_,_) (Header lev ("",cls,kvs) ils:rest) -> blocksToTypst (Header lev (ident,cls,kvs) ils:rest) |
