@@ -831,23 +831,30 @@ reference = do notFollowedBy' (string "[^") -- footnote reference
831831 return $ normalizeSpaces result
832832
833833-- source for a link, with optional title
834−source = try $ do
835− char '('
834+source =
835+ (try $ charsInBalanced '(' ')' >>= parseFromString source') <|>
836+ -- the following is needed for cases like: [ref](/url(a).
837+ (enclosed (char '(') (char ')') anyChar >>=
838+ parseFromString source')
839+
840+-- auxiliary function for source
841+source' = do
842+ skipSpaces
836843 src <- try (char '<' >>
837− many ((char '\\' >> anyChar) <|> noneOf "> \t\n") >>~
844+ many (optional (char '\\') >> noneOf "> \t\n") >>~
838845 char '>')
839− <|> many ((char '\\' >> anyChar) <|> noneOf ") \t\n")
846+ <|> many (optional (char '\\') >> noneOf " \t\n")
840847 tit <- option "" linkTitle
841848 skipSpaces
842− char ')'
849+ eof
843850 return (removeTrailingSpace src, tit)
844851
845852linkTitle = try $ do
846853 (many1 spaceChar >> option '\n' newline) <|> newline
847854 skipSpaces
848− delim <- char '\'' <|> char '"'
849− tit <- manyTill anyChar (try (char delim >> skipSpaces >>
850− notFollowedBy (noneOf ")\n")))
855+ delim <- oneOf "'\""
856+ tit <- manyTill (optional (char '\\') >> anyChar)
857+ (try (char delim >> skipSpaces >> eof))
851858 return $ decodeCharacterReferences tit
852859
853860link = try $ do