Parsing.GridTable: remove use of unsafe function last

This commit is contained in:
Albert Krewinkel 2022-07-18 12:14:09 +02:00
parent 7999b0b96e
commit dfbfbfbf24
No known key found for this signature in database
GPG key ID: 388DC0B21F631124

View file

@ -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