@@ -57,6 +57,7 @@ import Text.TeXMath (writeEqn)
5757import System.FilePath (takeExtension)
5858import Skylighting
5959import Text.Pandoc.Highlighting
60+import Network.URI (escapeURIString, isAllowedInURI)
6061
6162data WriterState = WriterState { stHasInlineMath :: Bool
6263 , stFirstPara :: Bool
@@ -157,6 +158,9 @@ escapeBar = concatMap go
157158escapeString :: String -> String
158159escapeString = concatMap escapeChar
159160
161+escapeUri :: String -> String
162+escapeUri = escapeURIString (\c -> c /= '@' && isAllowedInURI c)
163+
160164toSmallCaps :: String -> String
161165toSmallCaps [] = []
162166toSmallCaps (c:cs)
@@ -509,7 +513,7 @@ inlineToMs opts (Link _ txt (src, _)) = do
509513 -- external link
510514 contents <- inlineListToMs' opts $ map breakToSpace txt
511515 return $ text "\\c" <> cr <> nowrap (text ".pdfhref W -D " <>
512− doubleQuotes (text src) <> text " -A " <>
516+ doubleQuotes (text (escapeUri src)) <> text " -A " <>
513517 doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
514518 text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
515519inlineToMs opts (Image attr alternate (source, tit)) = do