aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-07-16 15:49:53 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2013-07-16 15:50:39 -0700
commit8483b5756fbf45270a84fa3e9174081041ff5558 (patch)
treeeb7d3b405b42eb1cb14f4e4fbbd2b3491a550b97 /src
parent0bd5830ad4cbf056d18595208532082fe674c6d2 (diff)
downloadpandoc-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.hs12
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]