diff options
| author | John MacFarlane <[email protected]> | 2024-03-18 11:43:41 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-03-18 11:43:41 -0700 |
| commit | d89167d25f1d7fc44741472303fe60d8ad57d87f (patch) | |
| tree | 41f70c1aa109856c3ea417a09de3e506f2827bfb | |
| parent | eca2c82abd9782b61b31093fb6cfa848cab57d96 (diff) | |
Typst writer: more reliable escaping in inline `[..]` contexts.
For example, we need to escape `[\1. April]` or it will be
treated as an ordered list.
Closes #9586.
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 16 | ||||
| -rw-r--r-- | test/command/9586.md | 7 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index 976980d20..7c804ccd8 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -25,7 +25,8 @@ import Network.URI (unEscapeString) import qualified Data.Text as T import Control.Monad.State ( StateT, evalStateT, gets, modify ) import Text.Pandoc.Writers.Shared ( metaToContext, defField, resetField, - toLegacyTable, lookupMetaString ) + toLegacyTable, lookupMetaString, + isOrderedListMarker ) import Text.Pandoc.Shared (isTightList, orderedListMarkers, tshow) import Text.Pandoc.Writers.Math (convertMath) import qualified Text.TeXMath as TM @@ -232,9 +233,6 @@ 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) @@ -330,7 +328,15 @@ mkImage useBox src kvs textstyle :: PandocMonad m => Doc Text -> [Inline] -> TW m (Doc Text) textstyle s inlines = - (<> endCode) . (s <>) . brackets <$> inlinesToTypst inlines + (<> endCode) . (s <>) . brackets . addEscape <$> inlinesToTypst inlines + where + addEscape = + case inlines of + (Str t : _) + | isOrderedListMarker t -> ("\\" <>) + | Just (c, _) <- T.uncons t + , needsEscapeAtLineStart c -> ("\\" <>) + _ -> id escapeTypst :: EscapeContext -> Text -> Doc Text escapeTypst context t = diff --git a/test/command/9586.md b/test/command/9586.md new file mode 100644 index 000000000..aa7045189 --- /dev/null +++ b/test/command/9586.md @@ -0,0 +1,7 @@ +``` +% pandoc -t typst +**1. April 2024** +^D +#strong[\1. April 2024] + +``` |
