git.iko.soy/typeable/pandoc
on master help sign in
Percent-encode more special characters in URLs.
1e8a25aJohn MacFarlane
src/Text/Pandoc/Shared.hs+5−2
@@ -288,9 +288,12 @@ toRomanNumeral x =
288 _ | x >= 1 -> "I" ++ toRomanNumeral (x - 1)
288 _ | x >= 1 -> "I" ++ toRomanNumeral (x - 1)
289 _ -> ""
289 _ -> ""
290
290
291−-- | Escape whitespace in URI.
291+-- | Escape whitespace and some punctuation characters in URI.
292escapeURI :: String -> String
292escapeURI :: String -> String
293−escapeURI = escapeURIString (not . isSpace)
293+escapeURI = escapeURIString (not . needsEscaping)
294+ where needsEscaping c = isSpace c || c `elem`
295+ ['<','>','|','"','{','}','[',']','^', '`']
296+
294
297
295-- | Convert tabs to spaces and filter out DOS line endings.
298-- | Convert tabs to spaces and filter out DOS line endings.
296-- Tabs will be preserved if tab stop is set to 0.
299-- Tabs will be preserved if tab stop is set to 0.
src/Text/Pandoc/Writers/LaTeX.hs+5−5
@@ -242,7 +242,7 @@ stringToLaTeX ctx (x:xs) = do
242 '^' -> "\\^{}" ++ rest
242 '^' -> "\\^{}" ++ rest
243 '\\'| isUrl -> '/' : rest -- NB. / works as path sep even on Windows
243 '\\'| isUrl -> '/' : rest -- NB. / works as path sep even on Windows
244 | otherwise -> "\\textbackslash{}" ++ rest
244 | otherwise -> "\\textbackslash{}" ++ rest
245− '|' -> "\\textbar{}" ++ rest
245+ '|' | not isUrl -> "\\textbar{}" ++ rest
246 '<' -> "\\textless{}" ++ rest
246 '<' -> "\\textless{}" ++ rest
247 '>' -> "\\textgreater{}" ++ rest
247 '>' -> "\\textgreater{}" ++ rest
248 '[' -> "{[}" ++ rest -- to avoid interpretation as
248 '[' -> "{[}" ++ rest -- to avoid interpretation as
@@ -848,17 +848,17 @@ inlineToLaTeX (Link txt (src, _)) =
848 case txt of
848 case txt of
849 [Str x] | escapeURI x == src -> -- autolink
849 [Str x] | escapeURI x == src -> -- autolink
850 do modify $ \s -> s{ stUrl = True }
850 do modify $ \s -> s{ stUrl = True }
851− src' <- stringToLaTeX URLString src
851+ src' <- stringToLaTeX URLString (escapeURI src)
852 return $ text $ "\\url{" ++ src' ++ "}"
852 return $ text $ "\\url{" ++ src' ++ "}"
853 [Str x] | Just rest <- stripPrefix "mailto:" src,
853 [Str x] | Just rest <- stripPrefix "mailto:" src,
854 escapeURI x == rest -> -- email autolink
854 escapeURI x == rest -> -- email autolink
855 do modify $ \s -> s{ stUrl = True }
855 do modify $ \s -> s{ stUrl = True }
856− src' <- stringToLaTeX URLString src
856+ src' <- stringToLaTeX URLString (escapeURI src)
857 contents <- inlineListToLaTeX txt
857 contents <- inlineListToLaTeX txt
858 return $ "\\href" <> braces (text src') <>
858 return $ "\\href" <> braces (text src') <>
859 braces ("\\nolinkurl" <> braces contents)
859 braces ("\\nolinkurl" <> braces contents)
860 _ -> do contents <- inlineListToLaTeX txt
860 _ -> do contents <- inlineListToLaTeX txt
861− src' <- stringToLaTeX URLString src
861+ src' <- stringToLaTeX URLString (escapeURI src)
862 return $ text ("\\href{" ++ src' ++ "}{") <>
862 return $ text ("\\href{" ++ src' ++ "}{") <>
863 contents <> char '}'
863 contents <> char '}'
864inlineToLaTeX (Image _ (source, _)) = do
864inlineToLaTeX (Image _ (source, _)) = do
@@ -866,7 +866,7 @@ inlineToLaTeX (Image _ (source, _)) = do
866 let source' = if isURI source
866 let source' = if isURI source
867 then source
867 then source
868 else unEscapeString source
868 else unEscapeString source
869− source'' <- stringToLaTeX URLString source'
869+ source'' <- stringToLaTeX URLString (escapeURI source')
870 inHeading <- gets stInHeading
870 inHeading <- gets stInHeading
871 return $
871 return $
872 (if inHeading then "\\protect\\includegraphics" else "\\includegraphics")
872 (if inHeading then "\\protect\\includegraphics" else "\\includegraphics")
tests/Tests/Readers/Markdown.hs+4−2
@@ -66,9 +66,11 @@ bareLinkTests =
66 , ("http://en.wikipedia.org/wiki/Sprite_(computer_graphics)",
66 , ("http://en.wikipedia.org/wiki/Sprite_(computer_graphics)",
67 autolink "http://en.wikipedia.org/wiki/Sprite_(computer_graphics)")
67 autolink "http://en.wikipedia.org/wiki/Sprite_(computer_graphics)")
68 , ("http://en.wikipedia.org/wiki/Sprite_[computer_graphics]",
68 , ("http://en.wikipedia.org/wiki/Sprite_[computer_graphics]",
69+ link "http://en.wikipedia.org/wiki/Sprite_%5Bcomputer_graphics%5D" ""
69− autolink "http://en.wikipedia.org/wiki/Sprite_[computer_graphics]")
70+ (str "http://en.wikipedia.org/wiki/Sprite_[computer_graphics]"))
70 , ("http://en.wikipedia.org/wiki/Sprite_{computer_graphics}",
71 , ("http://en.wikipedia.org/wiki/Sprite_{computer_graphics}",
72+ link "http://en.wikipedia.org/wiki/Sprite_%7Bcomputer_graphics%7D" ""
71− autolink "http://en.wikipedia.org/wiki/Sprite_{computer_graphics}")
73+ (str "http://en.wikipedia.org/wiki/Sprite_{computer_graphics}"))
72 , ("http://example.com/Notification_Center-GitHub-20101108-140050.jpg",
74 , ("http://example.com/Notification_Center-GitHub-20101108-140050.jpg",
73 autolink "http://example.com/Notification_Center-GitHub-20101108-140050.jpg")
75 autolink "http://example.com/Notification_Center-GitHub-20101108-140050.jpg")
74 , ("https://github.com/github/hubot/blob/master/scripts/cream.js#L20-20",
76 , ("https://github.com/github/hubot/blob/master/scripts/cream.js#L20-20",