diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-03-09 11:46:00 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-03-09 11:46:00 -0800 |
commit | 2b55b76ebec87f4d35b2e641e054bd6dfc74be09 (patch) | |
tree | 1ea7aedc0b313669668f75efb9d29f78b51f83d3 /src/Text | |
parent | 54a68616d7f9259840fd8a884d806782a73236a9 (diff) | |
download | pandoc-2b55b76ebec87f4d35b2e641e054bd6dfc74be09.tar.gz |
Markdown reader: Improved pipe table parsing.
Fixes #2765.
Added test case.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index c99838352..b5d175453 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1376,25 +1376,25 @@ sepPipe = try $ do pipeTableRow :: MarkdownParser (F [Blocks]) pipeTableRow = try $ do scanForPipe - raw <- anyLine - parseFromString pipeTableRow' raw - -pipeTableRow' :: MarkdownParser (F [Blocks]) -pipeTableRow' = do skipMany spaceChar openPipe <- (True <$ char '|') <|> return False - let cell = mconcat <$> (many (notFollowedBy (char '|') >> inline)) - cells <- cell `sepEndBy1` (char '|') + -- split into cells + let chunk = void (code <|> rawHtmlInline <|> escapedChar <|> rawLaTeXInline') + <|> void (noneOf "|\n\r") + let cellContents = ((trim . snd) <$> withRaw (many chunk)) >>= + parseFromString pipeTableCell + cells <- cellContents `sepEndBy1` (char '|') -- surrounding pipes needed for a one-column table: guard $ not (length cells == 1 && not openPipe) - spaces >> eof - return $ do - cells' <- sequence cells - return $ map - (\ils -> - case trimInlines ils of - ils' | B.isNull ils' -> mempty - | otherwise -> B.plain $ ils') cells' + blankline + return $ sequence cells + +pipeTableCell :: MarkdownParser (F Blocks) +pipeTableCell = do + result <- many inline + if null result + then return mempty + else return $ B.plain . mconcat <$> sequence result pipeTableHeaderPart :: Parser [Char] st (Alignment, Int) pipeTableHeaderPart = try $ do |