git.iko.soy/typeable/pandoc
on master help sign in
Markdown: better handling of parentheses in URLs and quotation marks in titles.

+ source parser first tries to parse URL with balanced parentheses; if that doesn't work, it tries to parse everything beginning with '(' and ending with ')'. + source parser now uses an auxiliary function source'. + linkTitle parser simplified and improved, under assumption that it will be called in context of source'. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1156 788f1e2b-df1e-0410-8736-df70ead52e1b

commit05cbdf04fdbb4290197b201a720f3e1796efee5e authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateMon 24 Dec 2007, 04:22 (19 years ago) parentee6f06e
1 file changed+15−8
Text/Pandoc/Readers/Markdown.hs+15−8
Text/Pandoc/Readers/Markdown.hs+15−8
@@ -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