diff options
author | John MacFarlane <jgm@berkeley.edu> | 2013-07-16 15:49:53 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2013-07-16 15:50:39 -0700 |
commit | 8483b5756fbf45270a84fa3e9174081041ff5558 (patch) | |
tree | eb7d3b405b42eb1cb14f4e4fbbd2b3491a550b97 /src | |
parent | 0bd5830ad4cbf056d18595208532082fe674c6d2 (diff) | |
download | pandoc-8483b5756fbf45270a84fa3e9174081041ff5558.tar.gz |
HTML reader: Handle non-simple tables (#893).
Column widths are divided equally.
TODO: Get column widths from col tags if present.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/HTML.hs | 12 |
1 files changed, 9 insertions, 3 deletions
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] |