Skip to content

Commit

Permalink
Also escape % in URLs.
Browse files Browse the repository at this point in the history
This improves the fix to #9017 in commit
7c43546

An alternative would be to avoid backslash escaping `#` and `%`
in URLs, and instead always add `fragile` to the slide environment.
  • Loading branch information
jgm committed Aug 23, 2023
1 parent 7c43546 commit d21a9cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Text/Pandoc/Writers/LaTeX/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\\}"
Expand Down
6 changes: 3 additions & 3 deletions test/command/5340.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
```

0 comments on commit d21a9cd

Please sign in to comment.