@@ -144,7 +144,7 @@ atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
144144litChar :: MarkdownParser Char
145145litChar = escapedChar'
146146 <|> noneOf "\n"
147− <|> (newline >> notFollowedBy blankline >> return ' ')
147+ <|> try (newline >> notFollowedBy blankline >> return ' ')
148148
149149-- | Parse a sequence of inline elements between square brackets,
150150-- including inlines between balanced pairs of square brackets.
@@ -265,6 +265,9 @@ referenceKey = try $ do
265265 manyTill (escapedChar' <|> litChar) (char '>')
266266 src <- try betweenAngles <|> sourceURL
267267 tit <- option "" referenceTitle
268+ -- currently we just ignore MMD-style link/image attributes
269+ _kvs <- option [] $ guardEnabled Ext_link_attributes
270+ >> many (spnl >> keyValAttr)
268271 blanklines
269272 let target = (escapeURI $ trimr src, tit)
270273 st <- getState
@@ -279,11 +282,18 @@ referenceKey = try $ do
279282referenceTitle :: MarkdownParser String
280283referenceTitle = try $ do
281284 skipSpaces >> optional newline >> skipSpaces
282− tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
283− <|> do delim <- char '\'' <|> char '"'
284− manyTill litChar (try (char delim >> skipSpaces >>
285− notFollowedBy (noneOf ")\n")))
286− return $ fromEntities tit
285+ let parenTit = charsInBalanced '(' ')' litChar
286+ fromEntities <$> (quotedTitle '"' <|> quotedTitle '\'' <|> parenTit)
287+
288+-- A link title in quotes
289+quotedTitle :: Char -> MarkdownParser String
290+quotedTitle c = try $ do
291+ char c
292+ notFollowedBy spaces
293+ let pEnder = try $ char c >> notFollowedBy (satisfy isAlphaNum)
294+ let regChunk = many1 (noneOf ['\\','\n',c]) <|> count 1 litChar
295+ let nestedChunk = (\x -> [c] ++ x ++ [c]) <$> quotedTitle c
296+ unwords . words . concat <$> manyTill (nestedChunk <|> regChunk) pEnder
287297
288298-- | PHP Markdown Extra style abbreviation key. Currently
289299-- we just skip them, since Pandoc doesn't have an element for
@@ -1266,7 +1276,7 @@ escapedChar' :: MarkdownParser Char
12661276escapedChar' = try $ do
12671277 char '\\'
12681278 (guardEnabled Ext_all_symbols_escapable >> satisfy (not . isAlphaNum))
1269− <|> oneOf "\\`*_{}[]()>#+-.!~"
1279+ <|> oneOf "\\`*_{}[]()>#+-.!~\""
12701280
12711281escapedChar :: MarkdownParser (F Inlines)
12721282escapedChar = do
@@ -1481,37 +1491,22 @@ reference = do notFollowedBy' (string "[^") -- footnote reference
14811491
14821492-- source for a link, with optional title
14831493source :: MarkdownParser (String, String)
1484−source =
1485− (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
1486− -- the following is needed for cases like: [ref](/url(a).
1487− (enclosed (char '(') (char ')') litChar >>= parseFromString source')
1488−
1489−-- auxiliary function for source
1490−source' :: MarkdownParser (String, String)
1491−source' = do
1494+source = do
1495+ char '('
14921496 skipSpaces
1493− let nl = char '\n' >>~ notFollowedBy blankline
1494− let sourceURL = liftM unwords $ many $ try $ do
1495− notFollowedBy' linkTitle
1496− skipMany spaceChar
1497− optional nl
1498− skipMany spaceChar
1499− many1 $ escapedChar' <|> satisfy (not . isBlank)
1497+ let urlChunk = try $ notFollowedBy (oneOf "\"')") >>
1498+ (charsInBalanced '(' ')' litChar <|> count 1 litChar)
1499+ let sourceURL = (unwords . words . concat) <$> many urlChunk
15001500 let betweenAngles = try $
1501− char '<' >> manyTill (escapedChar' <|> noneOf ">\n" <|> nl) (char '>')
1501+ char '<' >> manyTill litChar (char '>')
15021502 src <- try betweenAngles <|> sourceURL
1503− tit <- option "" linkTitle
1503+ tit <- option "" $ try $ spnl >> linkTitle
15041504 skipSpaces
1505− eof
1505+ char ')'
15061506 return (escapeURI $ trimr src, tit)
15071507
15081508linkTitle :: MarkdownParser String
1509−linkTitle = try $ do
1510− (many1 spaceChar >> option '\n' newline) <|> newline
1511− skipSpaces
1512− delim <- oneOf "'\""
1513− tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
1514− return $ fromEntities tit
1509+linkTitle = fromEntities <$> (quotedTitle '"' <|> quotedTitle '\'')
15151510
15161511link :: MarkdownParser (F Inlines)
15171512link = try $ do