From b6339f9baadfca351a890ff399d7bf3eb4c0f075 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 9 Dec 2025 19:11:47 +0100 Subject: Typst writer: escape hyphens when needed. Closes #11334. --- src/Text/Pandoc/Writers/Typst.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') 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 -- cgit v1.2.3