Typst writer: fold lang into pickTypstAttributes.

This ensures that `lang` attributes will be set for both
Divs and Spans. Closes #11673.
This commit is contained in:
John MacFarlane
2026-06-06 22:49:45 +02:00
parent 6c9b8ec557
commit 16d66edb2a
2 changed files with 10 additions and 9 deletions
+4 -9
View File
@@ -138,6 +138,9 @@ pandocToTypst options (Pandoc meta blocks) = do
pickTypstAttrs :: [(Text, Text)] -> ([(Text, Text)],[(Text, Text)])
pickTypstAttrs = foldr go ([],[])
where
go ("lang",lang)
| Right l <- parseLang lang
= second (("lang", tshow (langLanguage l)):)
go (k,v) =
case T.splitOn ":" k of
["typst", "text", x] -> second ((x,v):)
@@ -385,17 +388,9 @@ blockToTypst block =
Div (ident,_,kvs) blocks -> do
let lab = toLabel FreestandingLabel ident
let (typstAttrs,typstTextAttrs) = pickTypstAttrs kvs
-- Handle lang attribute for Div elements
let langAttrs = case lookup "lang" kvs of
Nothing -> []
Just lang -> case parseLang lang of
Left _ -> []
Right l -> [("lang",
tshow (langLanguage l))]
let allTypstTextAttrs = typstTextAttrs ++ langAttrs
contents <- blocksToTypst blocks
return $ "#block" <> toTypstPropsListParens typstAttrs <> "["
$$ toTypstPoundSetText allTypstTextAttrs
$$ toTypstPoundSetText typstTextAttrs
$$ contents
$$ ("]" <+> lab)
+6
View File
@@ -0,0 +1,6 @@
```
% pandoc -t typst
[Bonjour]{lang=fr} world.
^D
#text(lang: "fr")[Bonjour] world.
```