diff options
Diffstat (limited to 'src/Text/Pandoc/Readers/Markdown.hs')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 1786c7f45..8806416a7 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -913,17 +913,18 @@ pipeTable headless = tableWith (pipeTableHeader headless) -- | Parse header for an pipe table. pipeTableHeader :: Bool -- ^ Headerless table -> Parser [Char] ParserState ([[Block]], [Alignment], [Int]) -pipeTableHeader headless = try $ do - optional blanklines - heads <- if headless - then return $ repeat [] - else pipeTableRow - aligns <- nonindentSpaces >> optional (char '|') >> - pipeTableHeaderPart `sepBy1` sepPipe - optional (char '|') - newline - let cols = length aligns - return (take cols heads, aligns, []) +pipeTableHeader headless = do + scanForPipe + try $ do + heads <- if headless + then return $ repeat [] + else pipeTableRow + aligns <- nonindentSpaces >> optional (char '|') >> + pipeTableHeaderPart `sepBy1` sepPipe + optional (char '|') + newline + let cols = length aligns + return (take cols heads, aligns, []) sepPipe :: Parser [Char] ParserState () sepPipe = try $ char '|' >> notFollowedBy blankline @@ -955,6 +956,10 @@ pipeTableHeaderPart = do (Nothing,Just _) -> AlignRight (Just _,Just _) -> AlignCenter +-- Succeed only if current line contains a pipe. +scanForPipe :: Parser [Char] st () +scanForPipe = lookAhead (manyTill (satisfy (/='\n')) (char '|')) >> return () + table :: Parser [Char] ParserState Block table = multilineTable False <|> simpleTable True <|> simpleTable False <|> multilineTable True <|> |