aboutsummaryrefslogtreecommitdiff
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
parentc365deaf1f16c9f42421f54bd92215c840575bb0 (diff)
Typst writer: escape hyphens when needed.
Closes #11334.
-rw-r--r--src/Text/Pandoc/Writers/Typst.hs10
-rw-r--r--test/command/10271.md2
-rw-r--r--test/command/8966.md2
3 files changed, 8 insertions, 6 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
diff --git a/test/command/10271.md b/test/command/10271.md
index 40f5c0a3e..3b529b8e3 100644
--- a/test/command/10271.md
+++ b/test/command/10271.md
@@ -16,7 +16,7 @@
% pandoc -f markdown-smart -t typst+smart
"don't do it---"
^D
-\"don\'t do it---\"
+\"don\'t do it-\-\-\"
```
```
diff --git a/test/command/8966.md b/test/command/8966.md
index de70fe720..3c41fc85f 100644
--- a/test/command/8966.md
+++ b/test/command/8966.md
@@ -3,7 +3,7 @@
**Samsonov T.E.** Shape-Adaptive Geometric Simplification of Heterogeneous Line Datasets / T. E. Samsonov, O. P. Yakimova // International Journal of Geographical Information Science. — 2017. — Vol. 31. — № 8. — pp. 1485-1520.
^D
#strong[Samsonov T.E.] Shape-Adaptive Geometric Simplification of
-Heterogeneous Line Datasets / T. E. Samsonov, O. P. Yakimova \/\/
+Heterogeneous Line Datasets / T. E. Samsonov, O. P. Yakimova /\/
International Journal of Geographical Information Science. --- 2017. ---
Vol. 31. --- № 8. --- pp.~1485-1520.
```