git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: Fixed bug with list items containing line breaks.
ea8b811John MacFarlane
src/Text/Pandoc/Readers/Textile.hs+15−9
@@ -200,7 +200,7 @@ hrule = try $ do
200-- strict in the nesting, sublist must start at exactly "parent depth
200-- strict in the nesting, sublist must start at exactly "parent depth
201-- plus one"
201-- plus one"
202anyList :: Parser [Char] ParserState Block
202anyList :: Parser [Char] ParserState Block
203−anyList = try $ ( (anyListAtDepth 1) <* blanklines )
203+anyList = try $ anyListAtDepth 1 <* blanklines
204
204
205-- | This allow one type of list to be nested into an other type,
205-- | This allow one type of list to be nested into an other type,
206-- provided correct nesting
206-- provided correct nesting
@@ -234,14 +234,23 @@ orderedListItemAtDepth = genericListItemAtDepth '#'
234genericListItemAtDepth :: Char -> Int -> Parser [Char] ParserState [Block]
234genericListItemAtDepth :: Char -> Int -> Parser [Char] ParserState [Block]
235genericListItemAtDepth c depth = try $ do
235genericListItemAtDepth c depth = try $ do
236 count depth (char c) >> optional attributes >> whitespace
236 count depth (char c) >> optional attributes >> whitespace
237− p <- inlines
237+ p <- many listInline
238+ newline
238 sublist <- option [] (singleton <$> anyListAtDepth (depth + 1))
239 sublist <- option [] (singleton <$> anyListAtDepth (depth + 1))
239− return ((Plain p):sublist)
240+ return (Plain p : sublist)
240
241
241-- | A definition list is a set of consecutive definition items
242-- | A definition list is a set of consecutive definition items
242definitionList :: Parser [Char] ParserState Block
243definitionList :: Parser [Char] ParserState Block
243definitionList = try $ DefinitionList <$> many1 definitionListItem
244definitionList = try $ DefinitionList <$> many1 definitionListItem
244
245
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+
245-- | A definition list item in textile begins with '- ', followed by
254-- | A definition list item in textile begins with '- ', followed by
246-- the term defined, then spaces and ":=". The definition follows, on
255-- the term defined, then spaces and ":=". The definition follows, on
247-- the same single line, or spaned on multiple line, after a line
256-- the same single line, or spaned on multiple line, after a line
@@ -250,10 +259,11 @@ definitionListItem :: Parser [Char] ParserState ([Inline], [[Block]])
250definitionListItem = try $ do
259definitionListItem = try $ do
251 string "- "
260 string "- "
252 term <- many1Till inline (try (whitespace >> string ":="))
261 term <- many1Till inline (try (whitespace >> string ":="))
253− def' <- inlineDef <|> multilineDef
262+ def' <- multilineDef <|> inlineDef
254 return (term, def')
263 return (term, def')
255 where inlineDef :: Parser [Char] ParserState [[Block]]
264 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
257 multilineDef :: Parser [Char] ParserState [[Block]]
267 multilineDef :: Parser [Char] ParserState [[Block]]
258 multilineDef = try $ do
268 multilineDef = try $ do
259 optional whitespace >> newline
269 optional whitespace >> newline
@@ -348,10 +358,6 @@ maybeExplicitBlock name blk = try $ do
348inline :: Parser [Char] ParserState Inline
358inline :: Parser [Char] ParserState Inline
349inline = choice inlineParsers <?> "inline"
359inline = choice inlineParsers <?> "inline"
350
360
351−-- | List of consecutive inlines before a newline
352−inlines :: Parser [Char] ParserState [Inline]
353−inlines = manyTill inline newline
354−
355-- | Inline parsers tried in order
361-- | Inline parsers tried in order
356inlineParsers :: [Parser [Char] ParserState Inline]
362inlineParsers :: [Parser [Char] ParserState Inline]
357inlineParsers = [ autoLink
363inlineParsers = [ autoLink
tests/textile-reader.native+4
@@ -38,6 +38,10 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
38 [[Plain [Str "asterisk",Space,Str "1"]]
38 [[Plain [Str "asterisk",Space,Str "1"]]
39 ,[Plain [Str "asterisk",Space,Str "2"]]
39 ,[Plain [Str "asterisk",Space,Str "2"]]
40 ,[Plain [Str "asterisk",Space,Str "3"]]]
40 ,[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"]]]
41,Header 2 [Str "Ordered"]
45,Header 2 [Str "Ordered"]
42,Para [Str "Tight",Str ":"]
46,Para [Str "Tight",Str ":"]
43,OrderedList (1,DefaultStyle,DefaultDelim)
47,OrderedList (1,DefaultStyle,DefaultDelim)
tests/textile-reader.textile+6
@@ -91,6 +91,12 @@ Asterisks tight:
91* asterisk 2
91* asterisk 2
92* asterisk 3
92* asterisk 3
93
93
94+With line breaks:
95+
96+* asterisk 1
97+newline
98+* asterisk 2
99+
94h2. Ordered
100h2. Ordered
95
101
96Tight:
102Tight: