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
This commit is contained in:
fiddlosopher 2007-12-24 04:22:41 +00:00
parent ee6f06ec05
commit 05cbdf04fd

View file

@ -831,23 +831,30 @@ reference = do notFollowedBy' (string "[^") -- footnote reference
return $ normalizeSpaces result
-- source for a link, with optional title
source = try $ do
char '('
source =
(try $ charsInBalanced '(' ')' >>= parseFromString source') <|>
-- the following is needed for cases like: [ref](/url(a).
(enclosed (char '(') (char ')') anyChar >>=
parseFromString source')
-- auxiliary function for source
source' = do
skipSpaces
src <- try (char '<' >>
many ((char '\\' >> anyChar) <|> noneOf "> \t\n") >>~
many (optional (char '\\') >> noneOf "> \t\n") >>~
char '>')
<|> many ((char '\\' >> anyChar) <|> noneOf ") \t\n")
<|> many (optional (char '\\') >> noneOf " \t\n")
tit <- option "" linkTitle
skipSpaces
char ')'
eof
return (removeTrailingSpace src, tit)
linkTitle = try $ do
(many1 spaceChar >> option '\n' newline) <|> newline
skipSpaces
delim <- char '\'' <|> char '"'
tit <- manyTill anyChar (try (char delim >> skipSpaces >>
notFollowedBy (noneOf ")\n")))
delim <- oneOf "'\""
tit <- manyTill (optional (char '\\') >> anyChar)
(try (char delim >> skipSpaces >> eof))
return $ decodeCharacterReferences tit
link = try $ do