@@ -199,7 +199,7 @@ where
199199import Prelude
200200import Control.Monad.Identity
201201import Control.Monad.Reader
202−import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper, isHexDigit,
202+import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper,
203203 isPunctuation, isSpace, ord, toLower, toUpper)
204204import Data.Default
205205import Data.List (intercalate, isSuffixOf, transpose)
@@ -591,25 +591,24 @@ uri = try $ do
591591 -- http://en.wikipedia.org/wiki/State_of_emergency_(disambiguation)
592592 -- as a URL, while NOT picking up the closing paren in
593593 -- (http://wikipedia.org). So we include balanced parens in the URL.
594− let isWordChar c = isAlphaNum c || c `elem` "#$%+/@\\_-&="
595− let wordChar = satisfy isWordChar
596− let percentEscaped = try $ char '%' >> skipMany1 (satisfy isHexDigit)
597− let entity = () <$ characterReference
598− let punct = skipMany1 (char ',')
599− <|> () <$ satisfy (\c -> not (isSpace c) && c /= '<' && c /= '>')
600− let uriChunk = skipMany1 wordChar
601− <|> percentEscaped
602− <|> entity
603− <|> try (punct >>
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))
594+ str <- concat <$> many1 (uriChunkBetween '(' ')'
595+ <|> uriChunkBetween '{' '}'
596+ <|> uriChunkBetween '[' ']'
597+ <|> uriChunk)
610598 str' <- option str $ char '/' >> return (str ++ "/")
611599 let uri' = scheme ++ ":" ++ fromEntities str'
612600 return (uri', escapeURI uri')
601+ where
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
607+ <|> percentEscaped
608+ <|> entity
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])
613612
614613mathInlineWith :: Stream s m Char => String -> String -> ParserT s st m String
615614mathInlineWith op cl = try $ do