From 8483b5756fbf45270a84fa3e9174081041ff5558 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 16 Jul 2013 15:49:53 -0700 Subject: HTML reader: Handle non-simple tables (#893). Column widths are divided equally. TODO: Get column widths from col tags if present. --- src/Text/Pandoc/Readers/HTML.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 56d35160c..35b667fb0 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -217,6 +217,7 @@ pTable = try $ do TagOpen _ _ <- pSatisfy (~== TagOpen "table" []) skipMany pBlank caption <- option [] $ pInTags "caption" inline >>~ skipMany pBlank + -- TODO actually read these and take width information from them skipMany $ (pInTags "col" block >> skipMany pBlank) <|> (pInTags "colgroup" block >> skipMany pBlank) head' <- option [] $ pOptInTag "thead" $ pInTags "tr" (pCell "th") @@ -229,10 +230,15 @@ pTable = try $ do isSinglePlain [Plain _] = True isSinglePlain _ = False let isSimple = all isSinglePlain $ concat (head':rows) - guard isSimple - let cols = maximum $ map length rows + let cols = length $ if null head' + then head rows + else head' + -- fail if there are colspans or rowspans + guard $ all (\r -> length r == cols) rows let aligns = replicate cols AlignLeft - let widths = replicate cols 0 + let widths = if isSimple + then replicate cols 0 + else replicate cols (1.0 / fromIntegral cols) return [Table caption aligns widths head' rows] pCell :: String -> TagParser [TableCell] -- cgit v1.2.3