mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 17:20:47 +08:00
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:
@@ -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)
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
```
|
||||
% pandoc -t typst
|
||||
[Bonjour]{lang=fr} world.
|
||||
^D
|
||||
#text(lang: "fr")[Bonjour] world.
|
||||
```
|
||||
Reference in New Issue
Block a user