HTML writer: use width on whole table if col widths sum to < 100%.
Otherwise some browsers display the table with the columns separated far apart.
This commit is contained in:
parent
893ba9863c
commit
7843b5759a
2 changed files with 12 additions and 5 deletions
|
@ -593,8 +593,15 @@ blockToHtml opts (Table capt aligns widths headers rows') = do
|
||||||
return $ H.thead (nl opts >> contents) >> nl opts
|
return $ H.thead (nl opts >> contents) >> nl opts
|
||||||
body' <- liftM (\x -> H.tbody (nl opts >> mconcat x)) $
|
body' <- liftM (\x -> H.tbody (nl opts >> mconcat x)) $
|
||||||
zipWithM (tableRowToHtml opts aligns) [1..] rows'
|
zipWithM (tableRowToHtml opts aligns) [1..] rows'
|
||||||
return $ H.table $ nl opts >> captionDoc >> coltags >> head' >>
|
let tbl = H.table $
|
||||||
body' >> nl opts
|
nl opts >> captionDoc >> coltags >> head' >> body' >> nl opts
|
||||||
|
let totalWidth = sum widths
|
||||||
|
-- When widths of columns are < 100%, we need to set width for the whole
|
||||||
|
-- table, or some browsers give us skinny columns with lots of space between:
|
||||||
|
return $ if totalWidth == 0 || totalWidth == 1
|
||||||
|
then tbl
|
||||||
|
else tbl ! A.style (toValue $ "width:" ++
|
||||||
|
show (round (totalWidth * 100) :: Int) ++ "%;")
|
||||||
|
|
||||||
tableRowToHtml :: WriterOptions
|
tableRowToHtml :: WriterOptions
|
||||||
-> [Alignment]
|
-> [Alignment]
|
||||||
|
|
|
@ -94,7 +94,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p>Multiline table with caption:</p>
|
<p>Multiline table with caption:</p>
|
||||||
<table>
|
<table style="width:79%;">
|
||||||
<caption>Here's the caption. It may span multiple lines.</caption>
|
<caption>Here's the caption. It may span multiple lines.</caption>
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col width="15%" />
|
<col width="15%" />
|
||||||
|
@ -126,7 +126,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p>Multiline table without caption:</p>
|
<p>Multiline table without caption:</p>
|
||||||
<table>
|
<table style="width:79%;">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col width="15%" />
|
<col width="15%" />
|
||||||
<col width="13%" />
|
<col width="13%" />
|
||||||
|
@ -180,7 +180,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p>Multiline table without column headers:</p>
|
<p>Multiline table without column headers:</p>
|
||||||
<table>
|
<table style="width:79%;">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col width="15%" />
|
<col width="15%" />
|
||||||
<col width="13%" />
|
<col width="13%" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue