git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: Fixed bug with list items containing line breaks.

Now pandoc correctly handles hard line breaks inside list items. Previously they broke list parsing. Thanks to Pablo Rodríguez for pointing out the problem.

commitea8b8114e125bb0237a58b3e70e7fba59436ed24 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 13 Oct 2012, 10:44 (14 years ago) parent4012875
3 files changed+25−9
src/Text/Pandoc/Readers/Textile.hs+15−9 tests/textile-reader.native+4 tests/textile-reader.textile+6
src/Text/Pandoc/Readers/Textile.hs+15−9
@@ -200,7 +200,7 @@ hrule = try $ do
200200-- strict in the nesting, sublist must start at exactly "parent depth
201201-- plus one"
202202anyList :: Parser [Char] ParserState Block
203−anyList = try $ ( (anyListAtDepth 1) <* blanklines )
203+anyList = try $ anyListAtDepth 1 <* blanklines
204204
205205-- | This allow one type of list to be nested into an other type,
206206-- provided correct nesting
@@ -234,14 +234,23 @@ orderedListItemAtDepth = genericListItemAtDepth '#'
234234genericListItemAtDepth :: Char -> Int -> Parser [Char] ParserState [Block]
235235genericListItemAtDepth c depth = try $ do
236236 count depth (char c) >> optional attributes >> whitespace
237− p <- inlines
237+ p <- many listInline
238+ newline
238239 sublist <- option [] (singleton <$> anyListAtDepth (depth + 1))
239− return ((Plain p):sublist)
240+ return (Plain p : sublist)
240241
241242-- | A definition list is a set of consecutive definition items
242243definitionList :: Parser [Char] ParserState Block
243244definitionList = try $ DefinitionList <$> many1 definitionListItem
244245
246+-- | List start character.
247+listStart :: Parser [Char] st Char
248+listStart = oneOf "*#-"
249+
250+listInline :: Parser [Char] ParserState Inline
251+listInline = try (notFollowedBy newline >> inline)
252+ <|> try (endline <* notFollowedBy listStart)
253+
245254-- | A definition list item in textile begins with '- ', followed by
246255-- the term defined, then spaces and ":=". The definition follows, on
247256-- the same single line, or spaned on multiple line, after a line
@@ -250,10 +259,11 @@ definitionListItem :: Parser [Char] ParserState ([Inline], [[Block]])
250259definitionListItem = try $ do
251260 string "- "
252261 term <- many1Till inline (try (whitespace >> string ":="))
253− def' <- inlineDef <|> multilineDef
262+ def' <- multilineDef <|> inlineDef
254263 return (term, def')
255264 where inlineDef :: Parser [Char] ParserState [[Block]]
256− inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
265+ inlineDef = liftM (\d -> [[Plain d]])
266+ $ optional whitespace >> many listInline <* newline
257267 multilineDef :: Parser [Char] ParserState [[Block]]
258268 multilineDef = try $ do
259269 optional whitespace >> newline
@@ -348,10 +358,6 @@ maybeExplicitBlock name blk = try $ do
348358inline :: Parser [Char] ParserState Inline
349359inline = choice inlineParsers <?> "inline"
350360
351−-- | List of consecutive inlines before a newline
352−inlines :: Parser [Char] ParserState [Inline]
353−inlines = manyTill inline newline
354−
355361-- | Inline parsers tried in order
356362inlineParsers :: [Parser [Char] ParserState Inline]
357363inlineParsers = [ autoLink
tests/textile-reader.native+4
@@ -38,6 +38,10 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
3838 [[Plain [Str "asterisk",Space,Str "1"]]
3939 ,[Plain [Str "asterisk",Space,Str "2"]]
4040 ,[Plain [Str "asterisk",Space,Str "3"]]]
41+,Para [Str "With",Space,Str "line",Space,Str "breaks",Str ":"]
42+,BulletList
43+ [[Plain [Str "asterisk",Space,Str "1",LineBreak,Str "newline"]]
44+ ,[Plain [Str "asterisk",Space,Str "2"]]]
4145,Header 2 [Str "Ordered"]
4246,Para [Str "Tight",Str ":"]
4347,OrderedList (1,DefaultStyle,DefaultDelim)
tests/textile-reader.textile+6
@@ -91,6 +91,12 @@ Asterisks tight:
9191* asterisk 2
9292* asterisk 3
9393
94+With line breaks:
95+
96+* asterisk 1
97+newline
98+* asterisk 2
99+
94100h2. Ordered
95101
96102Tight: