git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Fix parsing of consecutive lists.

Pandoc previously behaved like Markdown.pl for consecutive lists of different styles. Thus, the following would be parsed as a single ordered list, rather than an ordered list followed by an unordered list: 1. one 2. two - one - two This patch makes pandoc behave more sensibly, parsing this as two lists. Any change in list type (ordered/unordered) or in list number style will trigger a new list. Thus, the following will also be parsed as two lists: 1. one 2. two a. one b. two Since we regard this as a bug in Markdown.pl, and not something anyone would ever rely on, we do not preserve the old behavior even when `--strict` is selected.

commit5b7c209373a441c2c7b296031025baa56a9f0c43 authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 2 Jan 2012, 17:04 (15 years ago) parent9001506
3 files changed+33−11
src/Text/Pandoc/Readers/Markdown.hs+12−10 tests/markdown-reader-more.native+11−1 tests/markdown-reader-more.txt+10
src/Text/Pandoc/Readers/Markdown.hs+12−10
@@ -556,9 +556,9 @@ listLine = try $ do
556556 return $ concat chunks ++ "\n"
557557
558558-- parse raw text for one list item, excluding start marker and continuations
559−rawListItem :: GenParser Char ParserState [Char]
560−rawListItem = try $ do
561− listStart
559+rawListItem :: GenParser Char ParserState a -> GenParser Char ParserState [Char]
560+rawListItem start = try $ do
561+ start
562562 result <- many1 listLine
563563 blanks <- many blankline
564564 return $ concat result ++ blanks
@@ -581,9 +581,9 @@ listContinuationLine = try $ do
581581 result <- manyTill anyChar newline
582582 return $ result ++ "\n"
583583
584−listItem :: GenParser Char ParserState [Block]
585−listItem = try $ do
586− first <- rawListItem
584+listItem :: GenParser Char ParserState a -> GenParser Char ParserState [Block]
585+listItem start = try $ do
586+ first <- rawListItem start
587587 continuations <- many listContinuation
588588 -- parsing with ListItemState forces markers at beginning of lines to
589589 -- count as list item markers, even if not separated by blank space.
@@ -600,13 +600,15 @@ listItem = try $ do
600600orderedList :: GenParser Char ParserState Block
601601orderedList = try $ do
602602 (start, style, delim) <- lookAhead anyOrderedListStart
603− items <- many1 listItem
603+ items <- many1 $ listItem $ try $
604+ do optional newline -- if preceded by a Plain block in a list context
605+ skipNonindentSpaces
606+ orderedListMarker style delim
604607 return $ OrderedList (start, style, delim) $ compactify items
605608
606609bulletList :: GenParser Char ParserState Block
607−bulletList = try $ do
608− lookAhead bulletListStart
609− many1 listItem >>= return . BulletList . compactify
610+bulletList =
611+ many1 (listItem bulletListStart) >>= return . BulletList . compactify
610612
611613-- definition lists
612614
tests/markdown-reader-more.native+11−1
@@ -47,4 +47,14 @@
4747,Para [Link [Str "bat"] ("/bat","")]
4848,Header 2 [Str "Curly",Space,Str "smart",Space,Str "quotes"]
4949,Para [Quoted DoubleQuote [Str "Hi"]]
50−,Para [Quoted SingleQuote [Str "Hi"]]]
50+,Para [Quoted SingleQuote [Str "Hi"]]
51+,Header 2 [Str "Consecutive",Space,Str "lists"]
52+,BulletList
53+ [[Plain [Str "one"]]
54+ ,[Plain [Str "two"]]]
55+,OrderedList (1,Decimal,Period)
56+ [[Plain [Str "one"]]
57+ ,[Plain [Str "two"]]]
58+,OrderedList (1,LowerAlpha,Period)
59+ [[Plain [Str "one"]]
60+ ,[Plain [Str "two"]]]]
tests/markdown-reader-more.txt+10
@@ -123,3 +123,13 @@ $\tuple{x,y}$
123123“Hi”
124124
125125‘Hi’
126+
127+## Consecutive lists
128+
129+- one
130+- two
131+1. one
132+2. two
133+
134+ a. one
135+ b. two