git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: simplify table parsing
2537c33Alexander Krotov
src/Text/Pandoc/Readers/Muse.hs+6−10
@@ -680,12 +680,8 @@ museAppendElement element tbl =
680 MuseFooterRow row -> tbl{ museTableFooters = row : museTableFooters tbl }
680 MuseFooterRow row -> tbl{ museTableFooters = row : museTableFooters tbl }
681 MuseCaption inlines -> tbl{ museTableCaption = inlines }
681 MuseCaption inlines -> tbl{ museTableCaption = inlines }
682
682
683−tableCell :: PandocMonad m => MuseParser m (F Blocks)
684−tableCell = try $ fmap B.plain . trimInlinesF . mconcat <$> manyTill inline (lookAhead cellEnd)
685− where cellEnd = try $ void (many1 spaceChar *> char '|') <|> eol
686−
687tableElements :: PandocMonad m => MuseParser m (F [MuseTableElement])
683tableElements :: PandocMonad m => MuseParser m (F [MuseTableElement])
688−tableElements = sequence <$> (tableParseElement `sepEndBy1` eol)
684+tableElements = sequence <$> many1 tableParseElement
689
685
690elementsToTable :: [MuseTableElement] -> MuseTable
686elementsToTable :: [MuseTableElement] -> MuseTable
691elementsToTable = foldr museAppendElement emptyTable
687elementsToTable = foldr museAppendElement emptyTable
@@ -704,10 +700,10 @@ tableParseElement = tableParseHeader
704tableParseRow :: PandocMonad m
700tableParseRow :: PandocMonad m
705 => Int -- ^ Number of separator characters
701 => Int -- ^ Number of separator characters
706 -> MuseParser m (F [Blocks])
702 -> MuseParser m (F [Blocks])
707−tableParseRow n = try $
703+tableParseRow n = try $ sequence <$> tableCells
708− sequence <$> (tableCell `sepBy2` fieldSep)
704+ where tableCells = (:) <$> tableCell sep <*> (tableCells <|> fmap pure (tableCell eol))
709− where p `sepBy2` sep = (:) <$> p <*> many1 (sep *> p)
705+ tableCell p = try $ fmap B.plain . trimInlinesF . mconcat <$> manyTill inline' p
710− fieldSep = many1 spaceChar *> count n (char '|') *> (void (many1 spaceChar) <|> void (lookAhead newline))
706+ sep = try $ many1 spaceChar *> count n (char '|') *> (void (many1 spaceChar) <|> void (lookAhead eol))
711
707
712-- | Parse a table header row.
708-- | Parse a table header row.
713tableParseHeader :: PandocMonad m => MuseParser m (F MuseTableElement)
709tableParseHeader :: PandocMonad m => MuseParser m (F MuseTableElement)
@@ -726,7 +722,7 @@ tableParseCaption :: PandocMonad m => MuseParser m (F MuseTableElement)
726tableParseCaption = try $ fmap MuseCaption . trimInlinesF . mconcat
722tableParseCaption = try $ fmap MuseCaption . trimInlinesF . mconcat
727 <$ many spaceChar
723 <$ many spaceChar
728 <* string "|+"
724 <* string "|+"
729− <*> many1Till inline (try $ string "+|")
725+ <*> many1Till inline (try $ string "+|" *> eol)
730
726
731-- ** Inline parsers
727-- ** Inline parsers
732
728