aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-12-09 19:11:47 +0100
committerJohn MacFarlane <[email protected]>2025-12-09 19:11:47 +0100
commitb6339f9baadfca351a890ff399d7bf3eb4c0f075 (patch)
tree741cd06f215f825134e58ba05c4371f5328a22c9 /src
parentc365deaf1f16c9f42421f54bd92215c840575bb0 (diff)
Typst writer: escape hyphens when needed.
Closes #11334.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Typst.hs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs
index e129fce69..42ca46534 100644
--- a/src/Text/Pandoc/Writers/Typst.hs
+++ b/src/Text/Pandoc/Writers/Typst.hs
@@ -584,11 +584,13 @@ escapeTypst smart context t =
| needsEscapeAtLineStart c || isOrderedListMarker t
-> afterBreak "\\"
_ -> mempty) <>
- (literal (T.replace "//" "\\/\\/"
- (if T.any needsEscape t
- then T.concatMap escapeChar t
- else t)))
+ literal (snd $ T.foldl' go ('\n', mempty) t)
where
+ go (lastc, t') c
+ | needsEscape c = (c, t' <> escapeChar c)
+ | c == '-', lastc == '-', smart = (c, t' <> T.pack ['\\',c])
+ | c == '/', lastc == '/' = (c, t' <> T.pack ['\\',c])
+ | otherwise = (c, T.snoc t' c)
escapeChar c
| c == '\160' = "~"
| c == '\8217', smart = "'" -- apostrophe