From 8a0e522c3901411e15c248a45fbc286b1ad35244 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 19 Feb 2024 08:52:37 -0800 Subject: Typst writer: ensure that `-`, `+`, etc. are escaped at beginning of block. Our recent relaxing of escaping (#9386) caused problems for things like emphasized `-` characters that were rendered using `#strong[-]#`. This now gets rendered as `#strong[\-]`. Closes #9478. --- src/Text/Pandoc/Writers/Typst.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index 9fc58b368..c9df66f77 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -218,6 +218,9 @@ listItemToTypst ind marker blocks = do return $ hang ind (marker <> space) contents inlinesToTypst :: PandocMonad m => [Inline] -> TW m (Doc Text) +inlinesToTypst ils@(Str t : _) -- need to escape - in '[-]' #9478 + | Just (c, _) <- T.uncons t + , needsEscapeAtLineStart c = ("\\" <>) . hcat <$> mapM inlineToTypst ils inlinesToTypst ils = hcat <$> mapM inlineToTypst ils inlineToTypst :: PandocMonad m => Inline -> TW m (Doc Text) @@ -360,11 +363,13 @@ escapeTypst context t = needsEscape '~' = True needsEscape ':' = context == TermContext needsEscape _ = False - needsEscapeAtLineStart '/' = True - needsEscapeAtLineStart '+' = True - needsEscapeAtLineStart '-' = True - needsEscapeAtLineStart '=' = True - needsEscapeAtLineStart _ = False + +needsEscapeAtLineStart :: Char -> Bool +needsEscapeAtLineStart '/' = True +needsEscapeAtLineStart '+' = True +needsEscapeAtLineStart '-' = True +needsEscapeAtLineStart '=' = True +needsEscapeAtLineStart _ = False data LabelType = FreestandingLabel -- cgit v1.2.3