git.iko.soy/typeable/pandoc
on master help sign in
Markdown/RST writers: Only autolink absolute URIs.
931b221John MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+3−1
@@ -44,6 +44,7 @@ import qualified Data.Set as Set
44import Text.Pandoc.Writers.HTML (writeHtmlString)
44import Text.Pandoc.Writers.HTML (writeHtmlString)
45import Text.Pandoc.Readers.TeXMath (readTeXMath)
45import Text.Pandoc.Readers.TeXMath (readTeXMath)
46import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
46import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
47+import Network.URI (isAbsoluteURI)
47import Data.Default
48import Data.Default
48
49
49type Notes = [[Block]]
50type Notes = [[Block]]
@@ -680,7 +681,8 @@ inlineToMarkdown opts (Link txt (src, tit)) = do
680 then empty
681 then empty
681 else text $ " \"" ++ tit ++ "\""
682 else text $ " \"" ++ tit ++ "\""
682 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
683 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
684+ let useAuto = isAbsoluteURI src &&
683− let useAuto = case txt of
685+ case txt of
684 [Str s] | escapeURI s == srcSuffix -> True
686 [Str s] | escapeURI s == srcSuffix -> True
685 _ -> False
687 _ -> False
686 let useRefLinks = writerReferenceLinks opts && not useAuto
688 let useRefLinks = writerReferenceLinks opts && not useAuto
src/Text/Pandoc/Writers/RST.hs+5−3
@@ -36,6 +36,7 @@ import Text.Pandoc.Options
36import Text.Pandoc.Shared
36import Text.Pandoc.Shared
37import Text.Pandoc.Templates (renderTemplate)
37import Text.Pandoc.Templates (renderTemplate)
38import Data.List ( isPrefixOf, intersperse, transpose )
38import Data.List ( isPrefixOf, intersperse, transpose )
39+import Network.URI (isAbsoluteURI)
39import Text.Pandoc.Pretty
40import Text.Pandoc.Pretty
40import Control.Monad.State
41import Control.Monad.State
41import Control.Applicative ( (<$>) )
42import Control.Applicative ( (<$>) )
@@ -364,9 +365,10 @@ inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
364inlineToRST Space = return space
365inlineToRST Space = return space
365-- autolink
366-- autolink
366inlineToRST (Link [Str str] (src, _))
367inlineToRST (Link [Str str] (src, _))
368+ | isAbsoluteURI src &&
367− | if "mailto:" `isPrefixOf` src
369+ if "mailto:" `isPrefixOf` src
368− then src == escapeURI ("mailto:" ++ str)
370+ then src == escapeURI ("mailto:" ++ str)
369− else src == escapeURI str = do
371+ else src == escapeURI str = do
370 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
372 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
371 return $ text srcSuffix
373 return $ text srcSuffix
372inlineToRST (Link [Image alt (imgsrc,imgtit)] (src, _tit)) = do
374inlineToRST (Link [Image alt (imgsrc,imgtit)] (src, _tit)) = do