aboutsummaryrefslogtreecommitdiff
path: root/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-12-24 04:22:41 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-12-24 04:22:41 +0000
commit05cbdf04fdbb4290197b201a720f3e1796efee5e (patch)
tree61739e5b863b37e5828d487b0f739dffa9e01a10 /Text/Pandoc/Readers
parentee6f06ec05a405795aa80135a7eb3a012fe7ea27 (diff)
downloadpandoc-05cbdf04fdbb4290197b201a720f3e1796efee5e.tar.gz
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
Diffstat (limited to 'Text/Pandoc/Readers')
-rw-r--r--Text/Pandoc/Readers/Markdown.hs23
1 files changed, 15 insertions, 8 deletions
diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs
index 9dedd1fef..e9befec12 100644
--- a/Text/Pandoc/Readers/Markdown.hs
+++ b/Text/Pandoc/Readers/Markdown.hs
@@ -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