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.
This commit is contained in:
John MacFarlane
2024-02-19 08:52:37 -08:00
parent b36052144b
commit 8a0e522c39
2 changed files with 19 additions and 5 deletions
+10 -5
View File
@@ -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
+9
View File
@@ -0,0 +1,9 @@
```
% pandoc -t typst --wrap=preserve
**- a -
- b**
^D
#strong[\- a -
\- b]
```