From 16d66edb2abf3ea4ad74d7f7e4f437136c99a400 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 6 Jun 2026 22:49:45 +0200 Subject: [PATCH] Typst writer: fold `lang` into `pickTypstAttributes`. This ensures that `lang` attributes will be set for both Divs and Spans. Closes #11673. --- src/Text/Pandoc/Writers/Typst.hs | 13 ++++--------- test/command/11673.md | 6 ++++++ 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 test/command/11673.md diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index 0e324b6ae..198f678cf 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -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) diff --git a/test/command/11673.md b/test/command/11673.md new file mode 100644 index 000000000..6d4048fab --- /dev/null +++ b/test/command/11673.md @@ -0,0 +1,6 @@ +``` +% pandoc -t typst +[Bonjour]{lang=fr} world. +^D +#text(lang: "fr")[Bonjour] world. +```