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.
This commit is contained in:
John MacFarlane
2024-03-18 11:43:41 -07:00
parent eca2c82abd
commit d89167d25f
2 changed files with 18 additions and 5 deletions
+11 -5
View File
@@ -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 =
+7
View File
@@ -0,0 +1,7 @@
```
% pandoc -t typst
**1. April 2024**
^D
#strong[\1. April 2024]
```