diff options
author | defanor <defanor@uberspace.net> | 2017-12-11 16:39:11 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2017-12-11 16:39:11 +0300 |
commit | 688c9aeb5a2077609ed5ad4be3d15061a9d2dc7a (patch) | |
tree | 7aa4f9ec396da0887235c0883c03cd3415cf4c34 /Pancake | |
parent | 899fe454ac0b97082f18f752bb827b80a6ac73c1 (diff) |
Handle empty tables
Don't try to estimate column widths if it leads to division by zero.
Diffstat (limited to 'Pancake')
-rw-r--r-- | Pancake/Rendering.hs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Pancake/Rendering.hs b/Pancake/Rendering.hs index 0149655..6c6f4e2 100644 --- a/Pancake/Rendering.hs +++ b/Pancake/Rendering.hs @@ -436,8 +436,10 @@ renderBlock (P.Table caption aligns widths headers rows) = do ws <- if widthsAreSet then pure widths else do lens <- map sum . transpose <$> mapM (mapM (fmap (length . unstyled . concat . rLines) . renderCell 80)) rows - pure $ map (\l -> fromIntegral l / fromIntegral (sum lens) * 0.7 - + 1 / fromIntegral (length lens) * 0.3) lens + pure $ map (\l -> if sum lens == 0 || length lens == 0 + then 0 + else fromIntegral l / fromIntegral (sum lens) * 0.7 + + 1 / fromIntegral (length lens) * 0.3) lens let withHead = if all null headers then id else (headers :) mapM_ (\r -> renderBlock P.HorizontalRule >> tableRow ws r) (withHead rows) renderBlock P.HorizontalRule |