aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-03-07 19:35:14 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-03-07 19:35:14 +0000
commit0943d24e479e5b1e2424354d5db15d339bd927ec (patch)
tree31e7b920c99b575ea4a5814cae34d2f7f26f6ccd
parente9de86de2df265de24a937d14146518042af1bc3 (diff)
downloadpandoc-0943d24e479e5b1e2424354d5db15d339bd927ec.tar.gz
HTML writer: Fixed multiline tables with no header.
In this case, the widths must be in the first table row. In the process, simplified table generation code. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1864 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 386fae6be..b337572fe 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -346,21 +346,28 @@ blockToHtml opts (Table capt aligns widths headers rows') = do
captionDoc <- if null capt
then return noHtml
else inlineListToHtml opts capt >>= return . caption
- colHeads <- colHeadsToHtml opts alignStrings widths headers
- rows'' <- zipWithM (tableRowToHtml opts alignStrings) (cycle ["odd", "even"]) rows'
- return $ table $ captionDoc +++ colHeads +++ rows''
-
-colHeadsToHtml :: WriterOptions
- -> [[Char]]
- -> [Double]
- -> [[Block]]
+ let zeros = replicate (length headers) (0.0 :: Double)
+ let (rownums, rows'') = if all null headers
+ then ([1..], rows')
+ else ([0..], (headers : rows'))
+ body' <- mapM (tableRowToHtml opts alignStrings) $
+ zip3 rownums (widths : repeat zeros) rows''
+ return $ table $ captionDoc +++ body'
+
+tableRowToHtml :: WriterOptions
+ -> [String]
+ -> (Int, [Double], [[Block]])
-> State WriterState Html
-colHeadsToHtml _ _ _ headers | all null headers = return noHtml
-colHeadsToHtml opts alignStrings widths headers = do
- heads <- sequence $ zipWith3
- (\alignment columnwidth item -> tableItemToHtml opts th alignment columnwidth item)
- alignStrings widths headers
- return $ tr ! [theclass "header"] $ toHtmlFromList heads
+tableRowToHtml opts alignStrings (rownum, widths, cols') = do
+ let mkcell = if rownum == 0 then th else td
+ let rowclass = case rownum of
+ 0 -> "header"
+ x | x `rem` 2 == 1 -> "odd"
+ _ -> "even"
+ cols'' <- sequence $ zipWith3
+ (\alignment columnwidth item -> tableItemToHtml opts mkcell alignment columnwidth item)
+ alignStrings widths cols'
+ return $ tr ! [theclass rowclass] $ toHtmlFromList cols''
alignmentToString :: Alignment -> [Char]
alignmentToString alignment = case alignment of
@@ -369,15 +376,6 @@ alignmentToString alignment = case alignment of
AlignCenter -> "center"
AlignDefault -> "left"
-tableRowToHtml :: WriterOptions
- -> [[Char]]
- -> String
- -> [[Block]]
- -> State WriterState Html
-tableRowToHtml opts aligns rowclass columns =
- (sequence $ zipWith3 (tableItemToHtml opts td) aligns (repeat 0) columns) >>=
- return . (tr ! [theclass rowclass]) . toHtmlFromList
-
tableItemToHtml :: WriterOptions
-> (Html -> Html)
-> [Char]