diff --git a/src/Text/Pandoc/Readers/HTML/Table.hs b/src/Text/Pandoc/Readers/HTML/Table.hs index b452a60ac..75684fee9 100644 --- a/src/Text/Pandoc/Readers/HTML/Table.hs +++ b/src/Text/Pandoc/Readers/HTML/Table.hs @@ -28,7 +28,7 @@ import Text.Pandoc.CSS (cssAttributes) import Text.Pandoc.Definition import Text.Pandoc.Class.PandocMonad (PandocMonad (..)) import Text.Pandoc.Parsing - ( eof, lookAhead, many, many1, manyTill, option, optional + ( eof, lookAhead, many, many1, manyTill, notFollowedBy, option, optional , optionMaybe, skipMany, try ) import Text.Pandoc.Readers.HTML.Parsing import Text.Pandoc.Readers.HTML.Types (TagParser) @@ -134,7 +134,8 @@ pRow block = try $ do skipMany pBlank TagOpen _ attribs <- pSatisfy (matchTagOpen "tr" []) <* skipMany pBlank cells <- many (pCell block BodyCell <|> pCell block HeaderCell) - TagClose _ <- pSatisfy (matchTagClose "tr") + -- the closing tag may be omitted (it is optional in HTML): + optional $ pSatisfy (matchTagClose "tr") let numheadcells = length $ takeWhile (\(ct,_) -> ct == HeaderCell) cells return (numheadcells, Row (toAttr attribs) $ map snd cells) @@ -145,9 +146,15 @@ pHeaderRow :: PandocMonad m -> TagParser m B.Row pHeaderRow block = try $ do skipMany pBlank - let pThs = many (snd <$> pCell block HeaderCell) - let mkRow (attribs, cells) = Row (toAttr attribs) cells - mkRow <$> pInTagWithAttribs TagsRequired "tr" pThs + TagOpen _ attribs <- pSatisfy (matchTagOpen "tr" []) + cells <- many (snd <$> pCell block HeaderCell) + skipMany pBlank + -- a header row may contain only