@@ -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))
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 '('
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