aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-10-11 17:06:26 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-10-11 17:12:50 -0700
commit1e8a25ad69db8fa372ac4ddbb5ac05ffb00ed052 (patch)
tree3fe6a71ece6682bcf86b66a83051a573c448de33 /src/Text
parent04307a155407480c2bedd4c6f9c121640ba47b11 (diff)
downloadpandoc-1e8a25ad69db8fa372ac4ddbb5ac05ffb00ed052.tar.gz
Percent-encode more special characters in URLs.
HTML, LaTeX writers adjusted. The special characters are '<','>','|','"','{','}','[',']','^', '`'. Closes #1640, #2377.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Shared.hs7
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs10
2 files changed, 10 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 1fe3db5f7..1e06aa383 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -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.
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index f424d8d4a..0caa80795 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -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")