From e90ce8e1ab4dc0fc441c59ea53cfd2733f587e96 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 18 Jul 2022 19:52:33 +0200 Subject: Unescape characters in `\lstinline` inside `\passthrough`. For full motivation, see #1629 ; this improves on 99e24cf18337b0b460005bf77e367783c34b75e7. Closes #8179. --- src/Text/Pandoc/Readers/LaTeX.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 988cc3055..f3aa29490 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -382,7 +382,8 @@ inlineCommands = M.unions , ("lowercase", makeLowercase <$> tok) , ("thanks", skipopts >> note <$> grouped block) , ("footnote", skipopts >> footnote) - , ("passthrough", tok) -- \passthrough macro used by latex writer + , ("passthrough", fixPassthroughEscapes <$> tok) + -- \passthrough macro used by latex writer -- for listings , ("includegraphics", do options <- option [] keyvals src <- braced @@ -473,6 +474,16 @@ alterStr :: (Text -> Text) -> Inline -> Inline alterStr f (Str xs) = Str (f xs) alterStr _ x = x +fixPassthroughEscapes :: Inlines -> Inlines +fixPassthroughEscapes = walk go + where + go (Code attr txt) = Code attr (T.pack $ unescapePassthrough $ T.unpack txt) + go x = x + unescapePassthrough [] = [] + unescapePassthrough ('\\':c:cs) + | c `elem` ['%','{','}','\\'] = c : unescapePassthrough cs + unescapePassthrough (c:cs) = c : unescapePassthrough cs + hyperlink :: PandocMonad m => LP m Inlines hyperlink = try $ do src <- untokenize <$> braced -- cgit v1.2.3