Markdown, RST writers: unescape URI in links, to make them readable.
(Since they aren't required to be escaped in these formats.)
This commit is contained in:
parent
8504055360
commit
14e7cb362a
2 changed files with 8 additions and 5 deletions
|
@ -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 })
|
||||
|
|
|
@ -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 ""] ||
|
||||
|
|
Loading…
Reference in a new issue