git.iko.soy/typeable/pandoc
on master help sign in
Simplify autolink parsing code, using Network.URI to test for

URIs. Added dependency on network library to debian/control and pandoc.cabal. git-svn-id: https://pandoc.googlecode.com/svn/trunk@982 788f1e2b-df1e-0410-8736-df70ead52e1b

commit76d462c1cd3e7b25e09d7d7efb23ff4a017344f2 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 1 Sep 2007, 17:22 (19 years ago) parentf8f9fa4
3 files changed+26−27
debian/control+1−1 pandoc.cabal+1−1 src/Text/Pandoc/Readers/Markdown.hs+24−25
debian/control+1−1
@@ -2,7 +2,7 @@ Source: pandoc
22Section: text
33Priority: optional
44Maintainer: 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
66Build-Depends-Indep: haddock
77Standards-Version: 3.7.2.0
88XS-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
3131 which convert this native representation into a target
3232 format. Thus, adding an input or output format requires
3333 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
3535Hs-Source-Dirs: src
3636Exposed-Modules: Text.Pandoc,
3737 Text.Pandoc.Blocks,
src/Text/Pandoc/Readers/Markdown.hs+24−25
@@ -31,9 +31,10 @@ module Text.Pandoc.Readers.Markdown (
3131 readMarkdown
3232 ) where
3333
34−import Data.List ( transpose, isSuffixOf, lookup, sortBy )
34+import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy )
3535import Data.Ord ( comparing )
3636import Data.Char ( isAlphaNum )
37+import Network.URI ( isURI )
3738import Text.Pandoc.Definition
3839import Text.Pandoc.Shared
3940import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXEnvironment )
@@ -738,9 +739,9 @@ doubleQuoted = try $ do
738739
739740failIfInQuoteContext context = do
740741 st <- getState
741− if (stateQuoteContext st == context)
742− then fail "already inside quotes"
743− else return ()
742+ if stateQuoteContext st == context
743+ then fail "already inside quotes"
744+ else return ()
744745
745746singleQuoteStart = do
746747 failIfInQuoteContext InSingleQuote
@@ -839,32 +840,30 @@ referenceLink label = do
839840 Nothing -> fail "no corresponding key"
840841 Just target -> return target
841842
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)
843849
844−-- a link <like@this.com>
845−autoLinkEmail = try $ do
846− char '<'
847− name <- many1Till (noneOf "/:<> \t\n") (char '@')
848− domain <- sepBy1 (many1 (noneOf "/:.@<> \t\n")) (char '.')
849− char '>'
850− let src = name ++ "@" ++ (joinWithSep "." domain)
851− txt <- autoLinkText src
852− return $ Link txt (("mailto:" ++ src), "")
850+uri = try $ do
851+ str <- many1 (noneOf "\n\t >")
852+ if isURI str
853+ then return str
854+ else fail "not a URI"
853855
854−-- a link <http://like.this.com>
855−autoLinkRegular = try $ do
856+autoLink = try $ do
856857 char '<'
857− prot <- oneOfStrings ["http:", "ftp:", "mailto:"]
858− rest <- many1Till (noneOf " \t\n<>") (char '>')
859− let src = prot ++ rest
860− txt <- autoLinkText src
861− return $ Link txt (src, "")
862−
863−autoLinkText src = do
858+ src <- uri <|> emailAddress
859+ char '>'
860+ let src' = if "mailto:" `isPrefixOf` src
861+ then drop 7 src
862+ else src
864863 st <- getState
865864 return $ if stateStrict st
866− then [Str src]
867− else [Code src]
865+ then Link [Str src'] (src, "")
866+ else Link [Code src'] (src, "")
868867
869868image = try $ do
870869 char '!'