Improved fix to #5340 and added test.

This commit is contained in:
John MacFarlane 2019-03-18 16:53:36 -07:00
parent c57649956d
commit 6be8f4e953
2 changed files with 16 additions and 2 deletions

View file

@ -1219,12 +1219,12 @@ inlineToLaTeX (Link _ txt ('#':ident, _)) = do
return $ text "\\protect\\hyperlink" <> braces (text lab) <> braces contents
inlineToLaTeX (Link _ txt (src, _)) =
case txt of
[Str x] | x == unEscapeString src -> -- autolink
[Str x] | unEscapeString x == unEscapeString src -> -- autolink
do modify $ \s -> s{ stUrl = True }
src' <- stringToLaTeX URLString (escapeURI src)
return $ text $ "\\url{" ++ src' ++ "}"
[Str x] | Just rest <- stripPrefix "mailto:" src,
x == unEscapeString rest -> -- email autolink
unEscapeString x == unEscapeString rest -> -- email autolink
do modify $ \s -> s{ stUrl = True }
src' <- stringToLaTeX URLString (escapeURI src)
contents <- inlineListToLaTeX txt

14
test/command/5340.md Normal file
View file

@ -0,0 +1,14 @@
```
% pandoc -f html -t latex --wrap=preserve
<a href="https://example.com/foo-bar">https://example.com/foo-bar</a>
<a href="https://example.com/foo--bar">https://example.com/foo--bar</a>
<a href="https://example.com/foo%2Dbar">https://example.com/foo-bar</a>
<a href="https://example.com/foo%2D%2Dbar">https://example.com/foo--bar</a>
<a href="https://example.com/foo%2D%2Dbar">https://example.com/foo%2D%2Dbar</a>
^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}
```