@@ -199,7 +199,7 @@ where
199import Prelude
199import Prelude
200import Control.Monad.Identity
200import Control.Monad.Identity
201import Control.Monad.Reader
201import Control.Monad.Reader
202−import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper, isHexDigit,
202+import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper,
203 isPunctuation, isSpace, ord, toLower, toUpper)
203 isPunctuation, isSpace, ord, toLower, toUpper)
204import Data.Default
204import Data.Default
205import Data.List (intercalate, isSuffixOf, transpose)
205import Data.List (intercalate, isSuffixOf, transpose)
@@ -591,25 +591,24 @@ uri = try $ do
591 -- http://en.wikipedia.org/wiki/State_of_emergency_(disambiguation)
591 -- http://en.wikipedia.org/wiki/State_of_emergency_(disambiguation)
592 -- as a URL, while NOT picking up the closing paren in
592 -- as a URL, while NOT picking up the closing paren in
593 -- (http://wikipedia.org). So we include balanced parens in the URL.
593 -- (http://wikipedia.org). So we include balanced parens in the URL.
594− let isWordChar c = isAlphaNum c || c `elem` "#$%+/@\\_-&="
594+ str <- concat <$> many1 (uriChunkBetween '(' ')'
595− let wordChar = satisfy isWordChar
595+ <|> uriChunkBetween '{' '}'
596− let percentEscaped = try $ char '%' >> skipMany1 (satisfy isHexDigit)
596+ <|> uriChunkBetween '[' ']'
597− let entity = () <$ characterReference
598− let punct = skipMany1 (char ',')
599− <|> () <$ satisfy (\c -> not (isSpace c) && c /= '<' && c /= '>')
600− let uriChunk = skipMany1 wordChar
604− lookAhead (void (satisfy isWordChar) <|> percentEscaped))
605− str <- snd <$> withRaw (skipMany1 ( () <$
606− (enclosed (char '(') (char ')') uriChunk
607− <|> enclosed (char '{') (char '}') uriChunk
608− <|> enclosed (char '[') (char ']') uriChunk)
609− <|> uriChunk))
597+ <|> uriChunk)
610 str' <- option str $ char '/' >> return (str ++ "/")
598 str' <- option str $ char '/' >> return (str ++ "/")
611 let uri' = scheme ++ ":" ++ fromEntities str'
599 let uri' = scheme ++ ":" ++ fromEntities str'
612 return (uri', escapeURI uri')
600 return (uri', escapeURI uri')
602+ wordChar = alphaNum <|> oneOf "#$%+/@\\_-&="
603+ percentEscaped = try $ (:) <$> char '%' <*> many1 hexDigit
604+ entity = try $ pure <$> characterReference
605+ punct = try $ many1 (char ',') <|> fmap pure (satisfy (\c -> not (isSpace c) && c /= '<' && c /= '>'))
606+ uriChunk = many1 wordChar
609+ <|> try (punct <* lookAhead (void wordChar <|> void percentEscaped))
610+ uriChunkBetween l r = try $ do chunk <- between (char l) (char r) uriChunk
611+ return ([l] ++ chunk ++ [r])
614mathInlineWith :: Stream s m Char => String -> String -> ParserT s st m String
613mathInlineWith :: Stream s m Char => String -> String -> ParserT s st m String
615mathInlineWith op cl = try $ do
614mathInlineWith op cl = try $ do