git.iko.soy/typeable/pandoc
on master help sign in
Simplify autolink parsing code, using Network.URI to test for
76d462cfiddlosopher
debian/control+1−1
@@ -2,7 +2,7 @@ Source: pandoc
2Section: text
2Section: text
3Priority: optional
3Priority: optional
4Maintainer: Recai Oktaş <roktas@debian.org>
4Maintainer: Recai Oktaş <roktas@debian.org>
5−Build-Depends: debhelper (>= 4.0.0), haskell-devscripts (>=0.5.12), ghc6 (>= 6.6-1), libghc6-xhtml-dev, libghc6-mtl-dev, perl
5+Build-Depends: debhelper (>= 4.0.0), haskell-devscripts (>=0.5.12), ghc6 (>= 6.6-1), libghc6-xhtml-dev, libghc6-mtl-dev, libghc6-network-dev, perl
6Build-Depends-Indep: haddock
6Build-Depends-Indep: haddock
7Standards-Version: 3.7.2.0
7Standards-Version: 3.7.2.0
8XS-Vcs-Svn: http://pandoc.googlecode.com/svn/trunk
8XS-Vcs-Svn: http://pandoc.googlecode.com/svn/trunk
pandoc.cabal+1−1
@@ -31,7 +31,7 @@ Description: Pandoc is a Haskell library for converting from one markup
31 which convert this native representation into a target
31 which convert this native representation into a target
32 format. Thus, adding an input or output format requires
32 format. Thus, adding an input or output format requires
33 only adding a reader or writer.
33 only adding a reader or writer.
34−Build-Depends: base, parsec, xhtml, mtl, regex-compat
34+Build-Depends: base, parsec, xhtml, mtl, regex-compat, network
35Hs-Source-Dirs: src
35Hs-Source-Dirs: src
36Exposed-Modules: Text.Pandoc,
36Exposed-Modules: Text.Pandoc,
37 Text.Pandoc.Blocks,
37 Text.Pandoc.Blocks,
src/Text/Pandoc/Readers/Markdown.hs+24−25
@@ -31,9 +31,10 @@ module Text.Pandoc.Readers.Markdown (
31 readMarkdown
31 readMarkdown
32 ) where
32 ) where
33
33
34−import Data.List ( transpose, isSuffixOf, lookup, sortBy )
34+import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy )
35import Data.Ord ( comparing )
35import Data.Ord ( comparing )
36import Data.Char ( isAlphaNum )
36import Data.Char ( isAlphaNum )
37+import Network.URI ( isURI )
37import Text.Pandoc.Definition
38import Text.Pandoc.Definition
38import Text.Pandoc.Shared
39import Text.Pandoc.Shared
39import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXEnvironment )
40import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXEnvironment )
@@ -738,9 +739,9 @@ doubleQuoted = try $ do
738
739
739failIfInQuoteContext context = do
740failIfInQuoteContext context = do
740 st <- getState
741 st <- getState
741− if (stateQuoteContext st == context)
742+ if stateQuoteContext st == context
742− then fail "already inside quotes"
743+ then fail "already inside quotes"
743− else return ()
744+ else return ()
744
745
745singleQuoteStart = do
746singleQuoteStart = do
746 failIfInQuoteContext InSingleQuote
747 failIfInQuoteContext InSingleQuote
@@ -839,32 +840,30 @@ referenceLink label = do
839 Nothing -> fail "no corresponding key"
840 Nothing -> fail "no corresponding key"
840 Just target -> return target
841 Just target -> return target
841
842
842−autoLink = autoLinkEmail <|> autoLinkRegular
843+emailAddress = try $ do
844+ name <- many1 (alphaNum <|> char '+')
845+ char '@'
846+ first <- many1 alphaNum
847+ rest <- many1 (char '.' >> many1 alphaNum)
848+ return $ "mailto:" ++ name ++ "@" ++ joinWithSep "." (first:rest)
843
849
844−-- a link <like@this.com>
850+uri = try $ do
845−autoLinkEmail = try $ do
846− char '<'
847− name <- many1Till (noneOf "/:<> \t\n") (char '@')
848− domain <- sepBy1 (many1 (noneOf "/:.@<> \t\n")) (char '.')
851+ str <- many1 (noneOf "\n\t >")
849− char '>'
852+ if isURI str
850− let src = name ++ "@" ++ (joinWithSep "." domain)
853+ then return str
851− txt <- autoLinkText src
854+ else fail "not a URI"
852− return $ Link txt (("mailto:" ++ src), "")
853
855
854−-- a link <http://like.this.com>
856+autoLink = try $ do
855−autoLinkRegular = try $ do
856 char '<'
857 char '<'
857− prot <- oneOfStrings ["http:", "ftp:", "mailto:"]
858+ src <- uri <|> emailAddress
858− rest <- many1Till (noneOf " \t\n<>") (char '>')
859+ char '>'
859− let src = prot ++ rest
860+ let src' = if "mailto:" `isPrefixOf` src
860− txt <- autoLinkText src
861+ then drop 7 src
861− return $ Link txt (src, "")
862+ else src
862−
863−autoLinkText src = do
864 st <- getState
863 st <- getState
865 return $ if stateStrict st
864 return $ if stateStrict st
866− then [Str src]
865+ then Link [Str src'] (src, "")
867− else [Code src]
866+ else Link [Code src'] (src, "")
868
867
869image = try $ do
868image = try $ do
870 char '!'
869 char '!'