@@ -108,6 +108,11 @@ atMostSpaces :: Int -> GenParser Char ParserState ()
108108atMostSpaces 0 = notFollowedBy (char ' ')
109109atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
110110
111+litChar :: GenParser Char ParserState Char
112+litChar = escapedChar'
113+ <|> noneOf "\n"
114+ <|> (newline >> notFollowedBy blankline >> return ' ')
115+
111116-- | Fail unless we're at beginning of a line.
112117failUnlessBeginningOfLine :: GenParser tok st ()
113118failUnlessBeginningOfLine = do
@@ -233,12 +238,12 @@ referenceKey = try $ do
233238 -- return blanks so line count isn't affected
234239 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
235240
236−referenceTitle :: GenParser Char st String
237−referenceTitle = try $ do
241+referenceTitle :: GenParser Char ParserState String
242+referenceTitle = try $ do
238243 skipSpaces >> optional newline >> skipSpaces
239− tit <- (charsInBalanced '(' ')' >>= return . unwords . words)
244+ tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
240245 <|> do delim <- char '\'' <|> char '"'
241− manyTill anyChar (try (char delim >> skipSpaces >>
246+ manyTill litChar (try (char delim >> skipSpaces >>
242247 notFollowedBy (noneOf ")\n")))
243248 return $ decodeCharacterReferences tit
244249
@@ -1136,9 +1141,9 @@ reference = do notFollowedBy' (string "[^") -- footnote reference
11361141 return $ normalizeSpaces result
11371142
11381143-- source for a link, with optional title
1139−source :: GenParser Char st (String, [Char])
1144+source :: GenParser Char ParserState (String, [Char])
11401145source =
1141− (try $ charsInBalanced '(' ')' >>= parseFromString source') <|>
1146+ (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
11421147 -- the following is needed for cases like: [ref](/url(a).
11431148 (enclosed (char '(') (char ')') anyChar >>=
11441149 parseFromString source')