aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-10-30 12:36:36 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-10-30 12:36:36 -0700
commit7843b5759a6c086dc29b7a2cdfa2bbb4ed2732ff (patch)
tree9e6c2dc28545c3a4bd5a09d7f46075ac38f3e162 /src/Text
parent893ba9863cc33bc1fa68bbd71c71db89205dfa00 (diff)
downloadpandoc-7843b5759a6c086dc29b7a2cdfa2bbb4ed2732ff.tar.gz
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index d06bec89f..9b362adf1 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -593,8 +593,15 @@ blockToHtml opts (Table capt aligns widths headers rows') = do
return $ H.thead (nl opts >> contents) >> nl opts
body' <- liftM (\x -> H.tbody (nl opts >> mconcat x)) $
zipWithM (tableRowToHtml opts aligns) [1..] rows'
- return $ H.table $ nl opts >> captionDoc >> coltags >> head' >>
- body' >> nl opts
+ let tbl = H.table $
+ 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
-> [Alignment]