From 688c9aeb5a2077609ed5ad4be3d15061a9d2dc7a Mon Sep 17 00:00:00 2001 From: defanor Date: Mon, 11 Dec 2017 16:39:11 +0300 Subject: Handle empty tables Don't try to estimate column widths if it leads to division by zero. --- Pancake/Rendering.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Pancake') 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 -- cgit v1.2.3