diff options
| author | Tuong Nguyen Manh <[email protected]> | 2025-08-24 13:11:26 +0200 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-08-26 18:25:08 +0200 |
| commit | 01f97ed55d7914a120b552c046a671c4623d7cd8 (patch) | |
| tree | 857eae4d413ae4cdb74660bfbf77e356119934b3 /src | |
| parent | 1bee23683d10b2e0ed4a539fecf510f01ad4523e (diff) | |
Typst Writer: Check XID_Continue in identifiers
Add unicode-data dependency for isXIDContinue for this to match the
rust implementation.
Also apply hlint suggestions for redundant $, literal pattern and
moving brackets to avoid $.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index e4db9ffc6..e9719e6db 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -42,8 +42,9 @@ import Text.DocTemplates (renderTemplate) import Text.Pandoc.Extensions (Extension(..)) import Text.Collate.Lang (Lang(..), parseLang) import Text.Printf (printf) -import Data.Char (isAlphaNum, isDigit) +import Data.Char (isDigit) import Data.Maybe (fromMaybe) +import Unicode.Char (isXIDContinue) -- | Convert Pandoc to Typst. writeTypst :: PandocMonad m => WriterOptions -> Pandoc -> m Text @@ -110,7 +111,7 @@ pandocToTypst options (Pandoc meta blocks) = do $ (if writerNumberSections options then defField "section-numbering" ("1.1.1.1.1" :: Text) else id) - $ metadata + metadata return $ render colwidth $ case writerTemplate options of Nothing -> main @@ -121,15 +122,15 @@ pickTypstAttrs = foldr go ([],[]) where go (k,v) = case T.splitOn ":" k of - "typst":"text":x:[] -> second ((x,v):) - "typst":x:[] -> first ((x,v):) + ["typst", "text", x] -> second ((x,v):) + ["typst", x] -> first ((x,v):) _ -> id formatTypstProp :: (Text, Text) -> Text formatTypstProp (k,v) = k <> ": " <> v toTypstPropsListSep :: [(Text, Text)] -> Doc Text -toTypstPropsListSep = hsep . intersperse "," . (map $ literal . formatTypstProp) +toTypstPropsListSep = hsep . intersperse "," . map (literal . formatTypstProp) toTypstPropsListTerm :: [(Text, Text)] -> Doc Text toTypstPropsListTerm [] = "" @@ -583,7 +584,7 @@ toLabel labelType ident ident' = T.pack $ unEscapeString $ T.unpack ident isIdentChar :: Char -> Bool -isIdentChar c = isAlphaNum c || c == '_' || c == '-' || c == '.' || c == ':' +isIdentChar c = isXIDContinue c || c == '_' || c == '-' || c == '.' || c == ':' toCite :: PandocMonad m => Citation -> TW m (Doc Text) toCite cite = do |
