From d21a9cd7f80cedb18d97cb92163ae7ec0f3a6237 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 23 Aug 2023 12:37:49 -0700 Subject: [PATCH] Also escape % in URLs. This improves the fix to #9017 in commit 7c4354646b57aa0d505dc955f856b8c3443c8db4 An alternative would be to avoid backslash escaping `#` and `%` in URLs, and instead always add `fragile` to the slide environment. --- src/Text/Pandoc/Writers/LaTeX/Util.hs | 5 ++++- test/command/5340.md | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Text/Pandoc/Writers/LaTeX/Util.hs b/src/Text/Pandoc/Writers/LaTeX/Util.hs index f19f5ddd56d1..79937e1fa3d1 100644 --- a/src/Text/Pandoc/Writers/LaTeX/Util.hs +++ b/src/Text/Pandoc/Writers/LaTeX/Util.hs @@ -94,9 +94,12 @@ stringToLaTeX context zs = do in case x of '\\'| isUrl -> emitc '/' -- NB. / works as path sep even on Windows '#' | isUrl -> emits "\\#" -- see #9014 + '%' | isUrl -> emits "\\%" -- see #9014 c | isUrl -> if c `elem` ['{', '}', '|', '^', '~', '[', ']', '`'] - then emits (escapeURIString (const False) [c]) + then do + emitc '\\' -- escape the % see #9014 + emits (escapeURIString (const False) [c]) else emitc c '{' -> emits "\\{" '}' -> emits "\\}" diff --git a/test/command/5340.md b/test/command/5340.md index dbf9c1b9aaf2..416f0bd6b55f 100644 --- a/test/command/5340.md +++ b/test/command/5340.md @@ -8,7 +8,7 @@ ^D \url{https://example.com/foo-bar} \url{https://example.com/foo--bar} -\url{https://example.com/foo%2Dbar} -\url{https://example.com/foo%2D%2Dbar} -\url{https://example.com/foo%2D%2Dbar} +\url{https://example.com/foo\%2Dbar} +\url{https://example.com/foo\%2D\%2Dbar} +\url{https://example.com/foo\%2D\%2Dbar} ```