From b6339f9baadfca351a890ff399d7bf3eb4c0f075 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 9 Dec 2025 19:11:47 +0100 Subject: [PATCH] Typst writer: escape hyphens when needed. Closes #11334. --- src/Text/Pandoc/Writers/Typst.hs | 10 ++++++---- test/command/10271.md | 2 +- test/command/8966.md | 2 +- 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. ```