aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2011-12-05 21:13:24 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2011-12-05 21:13:24 -0800
commit26371975f8ca40b6ca97bb5712f36aba99cccae5 (patch)
tree4f3b45a0d8ca17ed588f77e69e809902ca0c1303
parente021819ade4ca255ca3b653ea92fa507dee78407 (diff)
downloadpandoc-26371975f8ca40b6ca97bb5712f36aba99cccae5.tar.gz
Markdown: Better handling of escapes in link URLs and titles.
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index e2379bdc3..a5b39222b 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1145,11 +1145,10 @@ source :: GenParser Char ParserState (String, [Char])
source =
(try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
-- the following is needed for cases like: [ref](/url(a).
- (enclosed (char '(') (char ')') anyChar >>=
- parseFromString source')
+ (enclosed (char '(') (char ')') litChar >>= parseFromString source')
-- auxiliary function for source
-source' :: GenParser Char st (String, [Char])
+source' :: GenParser Char ParserState (String, [Char])
source' = do
skipSpaces
let nl = char '\n' >>~ notFollowedBy blankline
@@ -1158,22 +1157,21 @@ source' = do
skipMany spaceChar
optional nl
skipMany spaceChar
- many1 (satisfy $ not . isBlank)
- let betweenAngles = try $ char '<' >>
- manyTill (noneOf ">\n" <|> nl) (char '>')
+ many1 $ escapedChar' <|> satisfy (not . isBlank)
+ let betweenAngles = try $
+ char '<' >> manyTill (escapedChar' <|> noneOf ">\n" <|> nl) (char '>')
src <- try betweenAngles <|> sourceURL
tit <- option "" linkTitle
skipSpaces
eof
return (escapeURI $ removeTrailingSpace src, tit)
-linkTitle :: GenParser Char st String
-linkTitle = try $ do
+linkTitle :: GenParser Char ParserState String
+linkTitle = try $ do
(many1 spaceChar >> option '\n' newline) <|> newline
skipSpaces
delim <- oneOf "'\""
- tit <- manyTill (optional (char '\\') >> anyChar)
- (try (char delim >> skipSpaces >> eof))
+ tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
return $ decodeCharacterReferences tit
link :: GenParser Char ParserState Inline