Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/Text/Pandoc/Writers/Typst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" <>
Expand Down Expand Up @@ -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 <> ","
Expand All @@ -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
$$ ")")
Expand Down Expand Up @@ -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)
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.
```
Loading