From 0943d24e479e5b1e2424354d5db15d339bd927ec Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sun, 7 Mar 2010 19:35:14 +0000 Subject: 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 --- src/Text/Pandoc/Writers/HTML.hs | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'src/Text/Pandoc/Writers/HTML.hs') 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] -- cgit v1.2.3