Markdown reader: Correctly handle empty bullet list items.

For example:

    - one
    -
    - two

This should NOT be parsed as a setext header followed by a list.
This commit is contained in:
John MacFarlane 2013-11-03 21:16:47 -08:00
parent 732f6abe15
commit 4301fa4a27

View file

@ -444,6 +444,9 @@ block = choice [ mempty <$ blanklines
, codeBlockFenced , codeBlockFenced
, yamlMetaBlock , yamlMetaBlock
, guardEnabled Ext_latex_macros *> (macro >>= return . return) , guardEnabled Ext_latex_macros *> (macro >>= return . return)
-- note: bulletList needs to be before header because of
-- the possibility of empty list items: -
, bulletList
, header , header
, lhsCodeBlock , lhsCodeBlock
, rawTeXBlock , rawTeXBlock
@ -454,7 +457,6 @@ block = choice [ mempty <$ blanklines
, codeBlockIndented , codeBlockIndented
, blockQuote , blockQuote
, hrule , hrule
, bulletList
, orderedList , orderedList
, definitionList , definitionList
, noteBlock , noteBlock
@ -699,7 +701,7 @@ bulletListStart = try $ do
skipNonindentSpaces skipNonindentSpaces
notFollowedBy' (() <$ hrule) -- because hrules start out just like lists notFollowedBy' (() <$ hrule) -- because hrules start out just like lists
satisfy isBulletListMarker satisfy isBulletListMarker
spaceChar spaceChar <|> lookAhead newline
skipSpaces skipSpaces
anyOrderedListStart :: MarkdownParser (Int, ListNumberStyle, ListNumberDelim) anyOrderedListStart :: MarkdownParser (Int, ListNumberStyle, ListNumberDelim)
@ -727,7 +729,6 @@ listStart = bulletListStart <|> (anyOrderedListStart >> return ())
-- parse a line of a list item (start = parser for beginning of list item) -- parse a line of a list item (start = parser for beginning of list item)
listLine :: MarkdownParser String listLine :: MarkdownParser String
listLine = try $ do listLine = try $ do
notFollowedBy blankline
notFollowedBy' (do indentSpaces notFollowedBy' (do indentSpaces
many (spaceChar) many (spaceChar)
listStart) listStart)
@ -740,7 +741,7 @@ rawListItem :: MarkdownParser a
rawListItem start = try $ do rawListItem start = try $ do
start start
first <- listLine first <- listLine
rest <- many (notFollowedBy listStart >> listLine) rest <- many (notFollowedBy listStart >> notFollowedBy blankline >> listLine)
blanks <- many blankline blanks <- many blankline
return $ unlines (first:rest) ++ blanks return $ unlines (first:rest) ++ blanks