mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-12 02:25:57 +00:00
Percent-encode more special characters in URLs.
HTML, LaTeX writers adjusted.
The special characters are '<','>','|','"','{','}','[',']','^', '`'.
Closes #1640, #2377.
This commit is contained in:
@@ -288,9 +288,12 @@ toRomanNumeral x =
|
||||
_ | x >= 1 -> "I" ++ toRomanNumeral (x - 1)
|
||||
_ -> ""
|
||||
|
||||
-- | Escape whitespace in URI.
|
||||
-- | Escape whitespace and some punctuation characters in URI.
|
||||
escapeURI :: String -> String
|
||||
escapeURI = escapeURIString (not . isSpace)
|
||||
escapeURI = escapeURIString (not . needsEscaping)
|
||||
where needsEscaping c = isSpace c || c `elem`
|
||||
['<','>','|','"','{','}','[',']','^', '`']
|
||||
|
||||
|
||||
-- | Convert tabs to spaces and filter out DOS line endings.
|
||||
-- Tabs will be preserved if tab stop is set to 0.
|
||||
|
||||
@@ -242,7 +242,7 @@ stringToLaTeX ctx (x:xs) = do
|
||||
'^' -> "\\^{}" ++ rest
|
||||
'\\'| isUrl -> '/' : rest -- NB. / works as path sep even on Windows
|
||||
| otherwise -> "\\textbackslash{}" ++ rest
|
||||
'|' -> "\\textbar{}" ++ rest
|
||||
'|' | not isUrl -> "\\textbar{}" ++ rest
|
||||
'<' -> "\\textless{}" ++ rest
|
||||
'>' -> "\\textgreater{}" ++ rest
|
||||
'[' -> "{[}" ++ rest -- to avoid interpretation as
|
||||
@@ -848,17 +848,17 @@ inlineToLaTeX (Link txt (src, _)) =
|
||||
case txt of
|
||||
[Str x] | escapeURI x == src -> -- autolink
|
||||
do modify $ \s -> s{ stUrl = True }
|
||||
src' <- stringToLaTeX URLString src
|
||||
src' <- stringToLaTeX URLString (escapeURI src)
|
||||
return $ text $ "\\url{" ++ src' ++ "}"
|
||||
[Str x] | Just rest <- stripPrefix "mailto:" src,
|
||||
escapeURI x == rest -> -- email autolink
|
||||
do modify $ \s -> s{ stUrl = True }
|
||||
src' <- stringToLaTeX URLString src
|
||||
src' <- stringToLaTeX URLString (escapeURI src)
|
||||
contents <- inlineListToLaTeX txt
|
||||
return $ "\\href" <> braces (text src') <>
|
||||
braces ("\\nolinkurl" <> braces contents)
|
||||
_ -> do contents <- inlineListToLaTeX txt
|
||||
src' <- stringToLaTeX URLString src
|
||||
src' <- stringToLaTeX URLString (escapeURI src)
|
||||
return $ text ("\\href{" ++ src' ++ "}{") <>
|
||||
contents <> char '}'
|
||||
inlineToLaTeX (Image _ (source, _)) = do
|
||||
@@ -866,7 +866,7 @@ inlineToLaTeX (Image _ (source, _)) = do
|
||||
let source' = if isURI source
|
||||
then source
|
||||
else unEscapeString source
|
||||
source'' <- stringToLaTeX URLString source'
|
||||
source'' <- stringToLaTeX URLString (escapeURI source')
|
||||
inHeading <- gets stInHeading
|
||||
return $
|
||||
(if inHeading then "\\protect\\includegraphics" else "\\includegraphics")
|
||||
|
||||
@@ -66,9 +66,11 @@ bareLinkTests =
|
||||
, ("http://en.wikipedia.org/wiki/Sprite_(computer_graphics)",
|
||||
autolink "http://en.wikipedia.org/wiki/Sprite_(computer_graphics)")
|
||||
, ("http://en.wikipedia.org/wiki/Sprite_[computer_graphics]",
|
||||
autolink "http://en.wikipedia.org/wiki/Sprite_[computer_graphics]")
|
||||
link "http://en.wikipedia.org/wiki/Sprite_%5Bcomputer_graphics%5D" ""
|
||||
(str "http://en.wikipedia.org/wiki/Sprite_[computer_graphics]"))
|
||||
, ("http://en.wikipedia.org/wiki/Sprite_{computer_graphics}",
|
||||
autolink "http://en.wikipedia.org/wiki/Sprite_{computer_graphics}")
|
||||
link "http://en.wikipedia.org/wiki/Sprite_%7Bcomputer_graphics%7D" ""
|
||||
(str "http://en.wikipedia.org/wiki/Sprite_{computer_graphics}"))
|
||||
, ("http://example.com/Notification_Center-GitHub-20101108-140050.jpg",
|
||||
autolink "http://example.com/Notification_Center-GitHub-20101108-140050.jpg")
|
||||
, ("https://github.com/github/hubot/blob/master/scripts/cream.js#L20-20",
|
||||
|
||||
Reference in New Issue
Block a user