From dfbfbfbf2467ab7dff0ae2394ce0631540fae089 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 18 Jul 2022 12:14:09 +0200 Subject: Parsing.GridTable: remove use of unsafe function `last` --- src/Text/Pandoc/Parsing/GridTable.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Parsing/GridTable.hs b/src/Text/Pandoc/Parsing/GridTable.hs index b8ae26140..9db91fba7 100644 --- a/src/Text/Pandoc/Parsing/GridTable.hs +++ b/src/Text/Pandoc/Parsing/GridTable.hs @@ -26,6 +26,7 @@ where import Control.Monad (guard) import Data.List (transpose) import Data.Text (Text) +import Safe (lastDef) import Text.Pandoc.Options (ReaderOptions (readerColumns)) import Text.Pandoc.Builder (Blocks) import Text.Pandoc.Definition @@ -263,13 +264,13 @@ toHeaderRow = \case NoNormalization -> \l -> [toRow l | not (null l)] NormalizeHeader -> \l -> [toRow l | not (null l) && not (all null l)] --- Calculate relative widths of table columns, based on indices +-- | Calculate relative widths of table columns, based on indices widthsFromIndices :: Int -- Number of columns on terminal -> [Int] -- Indices -> [Double] -- Fractional relative sizes of columns widthsFromIndices _ [] = [] widthsFromIndices numColumns' indices = - let numColumns = max numColumns' (if null indices then 0 else last indices) + let numColumns = max numColumns' (lastDef 0 indices) lengths' = zipWith (-) indices (0:indices) lengths = reverse $ case reverse lengths' of -- cgit v1.2.3