diff options
author | John MacFarlane <jgm@berkeley.edu> | 2010-03-23 15:35:19 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2010-03-23 15:35:19 -0700 |
commit | 14e7cb362a1f0c339cd06fdf40a10889db27f4d1 (patch) | |
tree | 580e125adb6372e9f796b90731e800d419f4a3f9 /src/Text/Pandoc/Writers | |
parent | 85040553607d3f796e73e5eb23c9d9ac5d62ff9b (diff) | |
download | pandoc-14e7cb362a1f0c339cd06fdf40a10889db27f4d1.tar.gz |
Markdown, RST writers: unescape URI in links, to make them readable.
(Since they aren't required to be escaped in these formats.)
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 5 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 8 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index e93806e7b..fe8e0c2de 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -400,9 +400,10 @@ inlineToMarkdown _ (HtmlInline str) = return $ text str inlineToMarkdown _ (LineBreak) = return $ text " \n" inlineToMarkdown _ Space = return $ char ' ' inlineToMarkdown opts (Cite _ cits) = inlineListToMarkdown opts cits -inlineToMarkdown opts (Link txt (src, tit)) = do +inlineToMarkdown opts (Link txt (src', tit)) = do linktext <- inlineListToMarkdown opts txt let linktitle = if null tit then empty else text $ " \"" ++ tit ++ "\"" + let src = unescapeURI src' let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src let useRefLinks = writerReferenceLinks opts let useAuto = null tit && txt == [Code srcSuffix] @@ -423,7 +424,7 @@ inlineToMarkdown opts (Image alternate (source, tit)) = do (alternate == [Str source]) -- to prevent autolinks then [Str "image"] else alternate - linkPart <- inlineToMarkdown opts (Link txt (source, tit)) + linkPart <- inlineToMarkdown opts (Link txt (unescapeURI source, tit)) return $ char '!' <> linkPart inlineToMarkdown _ (Note contents) = do modify (\st -> st{ stNotes = contents : stNotes st }) diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index f22e31d7d..f4dfb2aa6 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -305,8 +305,9 @@ inlineToRST Space = return $ char ' ' inlineToRST (Link [Code str] (src, _)) | src == str || src == "mailto:" ++ str = do let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src - return $ text srcSuffix -inlineToRST (Link txt (src, tit)) = do + return $ text $ unescapeURI srcSuffix +inlineToRST (Link txt (src', tit)) = do + let src = unescapeURI src' useReferenceLinks <- get >>= (return . writerReferenceLinks . stOptions) linktext <- inlineListToRST $ normalizeSpaces txt if useReferenceLinks @@ -317,7 +318,8 @@ inlineToRST (Link txt (src, tit)) = do modify $ \st -> st { stLinks = refs' } return $ char '`' <> linktext <> text "`_" else return $ char '`' <> linktext <> text " <" <> text src <> text ">`_" -inlineToRST (Image alternate (source, tit)) = do +inlineToRST (Image alternate (source', tit)) = do + let source = unescapeURI source' pics <- get >>= (return . stImages) let labelsUsed = map fst pics let txt = if null alternate || alternate == [Str ""] || |