Skip to content

Commit 01f97ed

Browse files
TuongNMjgm
authored andcommitted
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 $.
1 parent 1bee236 commit 01f97ed

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

pandoc.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ library
542542
text-conversions >= 0.3 && < 0.4,
543543
time >= 1.5 && < 1.15,
544544
unicode-collation >= 0.1.1 && < 0.2,
545+
unicode-data >= 0.6 && < 0.7,
545546
unicode-transforms >= 0.3 && < 0.5,
546547
yaml >= 0.11 && < 0.12,
547548
libyaml >= 0.1.4 && < 0.2,

src/Text/Pandoc/Writers/Typst.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ import Text.DocTemplates (renderTemplate)
4242
import Text.Pandoc.Extensions (Extension(..))
4343
import Text.Collate.Lang (Lang(..), parseLang)
4444
import Text.Printf (printf)
45-
import Data.Char (isAlphaNum, isDigit)
45+
import Data.Char (isDigit)
4646
import Data.Maybe (fromMaybe)
47+
import Unicode.Char (isXIDContinue)
4748

4849
-- | Convert Pandoc to Typst.
4950
writeTypst :: PandocMonad m => WriterOptions -> Pandoc -> m Text
@@ -110,7 +111,7 @@ pandocToTypst options (Pandoc meta blocks) = do
110111
$ (if writerNumberSections options
111112
then defField "section-numbering" ("1.1.1.1.1" :: Text)
112113
else id)
113-
$ metadata
114+
metadata
114115
return $ render colwidth $
115116
case writerTemplate options of
116117
Nothing -> main
@@ -121,15 +122,15 @@ pickTypstAttrs = foldr go ([],[])
121122
where
122123
go (k,v) =
123124
case T.splitOn ":" k of
124-
"typst":"text":x:[] -> second ((x,v):)
125-
"typst":x:[] -> first ((x,v):)
125+
["typst", "text", x] -> second ((x,v):)
126+
["typst", x] -> first ((x,v):)
126127
_ -> id
127128

128129
formatTypstProp :: (Text, Text) -> Text
129130
formatTypstProp (k,v) = k <> ": " <> v
130131

131132
toTypstPropsListSep :: [(Text, Text)] -> Doc Text
132-
toTypstPropsListSep = hsep . intersperse "," . (map $ literal . formatTypstProp)
133+
toTypstPropsListSep = hsep . intersperse "," . map (literal . formatTypstProp)
133134

134135
toTypstPropsListTerm :: [(Text, Text)] -> Doc Text
135136
toTypstPropsListTerm [] = ""
@@ -583,7 +584,7 @@ toLabel labelType ident
583584
ident' = T.pack $ unEscapeString $ T.unpack ident
584585

585586
isIdentChar :: Char -> Bool
586-
isIdentChar c = isAlphaNum c || c == '_' || c == '-' || c == '.' || c == ':'
587+
isIdentChar c = isXIDContinue c || c == '_' || c == '-' || c == '.' || c == ':'
587588

588589
toCite :: PandocMonad m => Citation -> TW m (Doc Text)
589590
toCite cite = do

test/command/10816.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```
2+
% pandoc -f markdown -t typst
3+
# Test①
4+
^D
5+
= Test①
6+
#label("test①")
7+
```

0 commit comments

Comments
 (0)