git.iko.soy/typeable/pandoc
on master help sign in
Markdown/RST writers: Only autolink absolute URIs.

This fixes a regression and closes #830. $ echo '<a href="x">x</a>' | pandoc -f html -t markdown <x>

commit931b22184a63146e0e3cc30091f77796ace8f4d8 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 14 Apr 2013, 22:37 (14 years ago) parentd606d74
2 files changed+8−4
src/Text/Pandoc/Writers/Markdown.hs+3−1 src/Text/Pandoc/Writers/RST.hs+5−3
src/Text/Pandoc/Writers/Markdown.hs+3−1
@@ -44,6 +44,7 @@ import qualified Data.Set as Set
4444import Text.Pandoc.Writers.HTML (writeHtmlString)
4545import Text.Pandoc.Readers.TeXMath (readTeXMath)
4646import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
47+import Network.URI (isAbsoluteURI)
4748import Data.Default
4849
4950type Notes = [[Block]]
@@ -680,7 +681,8 @@ inlineToMarkdown opts (Link txt (src, tit)) = do
680681 then empty
681682 else text $ " \"" ++ tit ++ "\""
682683 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
683− let useAuto = case txt of
684+ let useAuto = isAbsoluteURI src &&
685+ case txt of
684686 [Str s] | escapeURI s == srcSuffix -> True
685687 _ -> False
686688 let useRefLinks = writerReferenceLinks opts && not useAuto
src/Text/Pandoc/Writers/RST.hs+5−3
@@ -36,6 +36,7 @@ import Text.Pandoc.Options
3636import Text.Pandoc.Shared
3737import Text.Pandoc.Templates (renderTemplate)
3838import Data.List ( isPrefixOf, intersperse, transpose )
39+import Network.URI (isAbsoluteURI)
3940import Text.Pandoc.Pretty
4041import Control.Monad.State
4142import Control.Applicative ( (<$>) )
@@ -364,9 +365,10 @@ inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
364365inlineToRST Space = return space
365366-- autolink
366367inlineToRST (Link [Str str] (src, _))
367− | if "mailto:" `isPrefixOf` src
368− then src == escapeURI ("mailto:" ++ str)
369− else src == escapeURI str = do
368+ | isAbsoluteURI src &&
369+ if "mailto:" `isPrefixOf` src
370+ then src == escapeURI ("mailto:" ++ str)
371+ else src == escapeURI str = do
370372 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
371373 return $ text srcSuffix
372374inlineToRST (Link [Image alt (imgsrc,imgtit)] (src, _tit)) = do