git.iko.soy/typeable/pandoc
on master help sign in
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

commit0943d24e479e5b1e2424354d5db15d339bd927ec authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 7 Mar 2010, 19:35 (17 years ago) parente9de86d
1 file changed+21−23
src/Text/Pandoc/Writers/HTML.hs+21−23
src/Text/Pandoc/Writers/HTML.hs+21−23
@@ -346,21 +346,28 @@ blockToHtml opts (Table capt aligns widths headers rows') = do
346346 captionDoc <- if null capt
347347 then return noHtml
348348 else inlineListToHtml opts capt >>= return . caption
349− colHeads <- colHeadsToHtml opts alignStrings widths headers
350− rows'' <- zipWithM (tableRowToHtml opts alignStrings) (cycle ["odd", "even"]) rows'
351− return $ table $ captionDoc +++ colHeads +++ rows''
352−
353−colHeadsToHtml :: WriterOptions
354− -> [[Char]]
355− -> [Double]
356− -> [[Block]]
349+ let zeros = replicate (length headers) (0.0 :: Double)
350+ let (rownums, rows'') = if all null headers
351+ then ([1..], rows')
352+ else ([0..], (headers : rows'))
353+ body' <- mapM (tableRowToHtml opts alignStrings) $
354+ zip3 rownums (widths : repeat zeros) rows''
355+ return $ table $ captionDoc +++ body'
356+
357+tableRowToHtml :: WriterOptions
358+ -> [String]
359+ -> (Int, [Double], [[Block]])
357360 -> State WriterState Html
358−colHeadsToHtml _ _ _ headers | all null headers = return noHtml
359−colHeadsToHtml opts alignStrings widths headers = do
360− heads <- sequence $ zipWith3
361− (\alignment columnwidth item -> tableItemToHtml opts th alignment columnwidth item)
362− alignStrings widths headers
363− return $ tr ! [theclass "header"] $ toHtmlFromList heads
361+tableRowToHtml opts alignStrings (rownum, widths, cols') = do
362+ let mkcell = if rownum == 0 then th else td
363+ let rowclass = case rownum of
364+ 0 -> "header"
365+ x | x `rem` 2 == 1 -> "odd"
366+ _ -> "even"
367+ cols'' <- sequence $ zipWith3
368+ (\alignment columnwidth item -> tableItemToHtml opts mkcell alignment columnwidth item)
369+ alignStrings widths cols'
370+ return $ tr ! [theclass rowclass] $ toHtmlFromList cols''
364371
365372alignmentToString :: Alignment -> [Char]
366373alignmentToString alignment = case alignment of
@@ -369,15 +376,6 @@ alignmentToString alignment = case alignment of
369376 AlignCenter -> "center"
370377 AlignDefault -> "left"
371378
372−tableRowToHtml :: WriterOptions
373− -> [[Char]]
374− -> String
375− -> [[Block]]
376− -> State WriterState Html
377−tableRowToHtml opts aligns rowclass columns =
378− (sequence $ zipWith3 (tableItemToHtml opts td) aligns (repeat 0) columns) >>=
379− return . (tr ! [theclass rowclass]) . toHtmlFromList
380−
381379tableItemToHtml :: WriterOptions
382380 -> (Html -> Html)
383381 -> [Char]