git.iko.soy/typeable/pandoc
on master help sign in
Changed uri parser so it doesn't include trailing punctuation.
6beba76John MacFarlane
src/Tests/Readers/RST.hs+8
@@ -45,5 +45,13 @@ tests = [ "field list" =:
45 , (str "Parameter i", [para "integer"])
45 , (str "Parameter i", [para "integer"])
46 , (str "Final", [para "item on two lines"])
46 , (str "Final", [para "item on two lines"])
47 ])
47 ])
48+ , "URLs with following punctuation" =:
49+ ("http://google.com, http://yahoo.com; http://foo.bar.baz.\n" ++
50+ "http://foo.bar/baz_(bam) (http://foo.bar)") =?>
51+ para (link "http://google.com" "" "http://google.com" +++ ", " +++
52+ link "http://yahoo.com" "" "http://yahoo.com" +++ "; " +++
53+ link "http://foo.bar.baz" "" "http://foo.bar.baz" +++ ". " +++
54+ link "http://foo.bar/baz_(bam)" "" "http://foo.bar/baz_(bam)"
55+ +++ " (" +++ link "http://foo.bar" "" "http://foo.bar" +++ ")")
48 ]
56 ]
49
57
src/Text/Pandoc/Parsing.hs+19−3
@@ -78,7 +78,7 @@ import Text.Pandoc.Generic
78import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
78import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
79import Text.ParserCombinators.Parsec
79import Text.ParserCombinators.Parsec
80import Text.Pandoc.CharacterReferences ( characterReference )
80import Text.Pandoc.CharacterReferences ( characterReference )
81−import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit )
81+import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
82import Data.List ( intercalate, transpose )
82import Data.List ( intercalate, transpose )
83import Network.URI ( parseURI, URI (..), isAllowedInURI )
83import Network.URI ( parseURI, URI (..), isAllowedInURI )
84import Control.Monad ( join, liftM, guard )
84import Control.Monad ( join, liftM, guard )
@@ -264,8 +264,24 @@ uri = try $ do
264 let protocols = [ "http:", "https:", "ftp:", "file:", "mailto:",
264 let protocols = [ "http:", "https:", "ftp:", "file:", "mailto:",
265 "news:", "telnet:" ]
265 "news:", "telnet:" ]
266 lookAhead $ oneOfStrings protocols
266 lookAhead $ oneOfStrings protocols
267− -- scan non-ascii characters and ascii characters allowed in a URI
267+ -- Scan non-ascii characters and ascii characters allowed in a URI.
268+ -- We allow punctuation except when followed by a space, since
269+ -- we don't want the trailing '.' in 'http://google.com.'
270+ let innerPunct = try $ satisfy isPunctuation >>~
271+ notFollowedBy (newline <|> spaceChar)
272+ let uriChar = innerPunct <|>
273+ satisfy (\c -> not (isPunctuation c) &&
268− str <- many1 $ satisfy (\c -> not (isAscii c) || isAllowedInURI c)
274+ (not (isAscii c) || isAllowedInURI c))
275+ -- We want to allow
276+ -- http://en.wikipedia.org/wiki/State_of_emergency_(disambiguation)
277+ -- as a URL, while NOT picking up the closing paren in
278+ -- (http://wikipedia.org)
279+ -- So we include balanced parens in the URL.
280+ let inParens = try $ do char '('
281+ res <- many uriChar
282+ char ')'
283+ return $ '(' : res ++ ")"
284+ str <- liftM concat $ many1 $ inParens <|> count 1 (innerPunct <|> uriChar)
269 -- now see if they amount to an absolute URI
285 -- now see if they amount to an absolute URI
270 case parseURI (escapeURI str) of
286 case parseURI (escapeURI str) of
271 Just uri' -> if uriScheme uri' `elem` protocols
287 Just uri' -> if uriScheme uri' `elem` protocols
src/Text/Pandoc/Readers/RST.hs+1−1
@@ -58,7 +58,7 @@ underlineChars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
58
58
59-- treat these as potentially non-text when parsing inline:
59-- treat these as potentially non-text when parsing inline:
60specialChars :: [Char]
60specialChars :: [Char]
61−specialChars = "\\`|*_<>$:[-.\"'\8216\8217\8220\8221"
61+specialChars = "\\`|*_<>$:[]()-.\"'\8216\8217\8220\8221"
62
62
63--
63--
64-- parsing documents
64-- parsing documents
tests/rst-reader.native+1−1
@@ -222,7 +222,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":
222,Para [Str "But",Space,Str "not",Space,Str "here",Str ":"]
222,Para [Str "But",Space,Str "not",Space,Str "here",Str ":"]
223,CodeBlock ("",[],[]) "http://example.com/"
223,CodeBlock ("",[],[]) "http://example.com/"
224,Header 1 [Str "Images"]
224,Header 1 [Str "Images"]
225−,Para [Str "From",Space,Quoted DoubleQuote [Str "Voyage",Space,Str "dans",Space,Str "la",Space,Str "Lune"],Space,Str "by",Space,Str "Georges",Space,Str "Melies",Space,Str "(1902)",Str ":"]
225+,Para [Str "From",Space,Quoted DoubleQuote [Str "Voyage",Space,Str "dans",Space,Str "la",Space,Str "Lune"],Space,Str "by",Space,Str "Georges",Space,Str "Melies",Space,Str "(",Str "1902",Str ")",Str ":"]
226,Plain [Image [Str "image"] ("lalune.jpg","")]
226,Plain [Image [Str "image"] ("lalune.jpg","")]
227,Plain [Image [Str "Voyage dans la Lune"] ("lalune.jpg","")]
227,Plain [Image [Str "Voyage dans la Lune"] ("lalune.jpg","")]
228,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image [Str "movie"] ("movie.jpg",""),Space,Str "icon",Str "."]
228,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image [Str "movie"] ("movie.jpg",""),Space,Str "icon",Str "."]