diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2024-02-19 08:52:37 -0800 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2024-02-19 08:52:37 -0800 |
| commit | 8a0e522c3901411e15c248a45fbc286b1ad35244 (patch) | |
| tree | 8225fc4a86bdb303560584c62c529ef4365ddf84 /src | |
| parent | b36052144b3fe49077ad70c6bd54d4747a4c0d03 (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 15 |
1 files changed, 10 insertions, 5 deletions
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 |
