aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2022-07-18 12:14:09 +0200
committerAlbert Krewinkel <[email protected]>2022-07-18 12:14:54 +0200
commitdfbfbfbf2467ab7dff0ae2394ce0631540fae089 (patch)
tree73e2e788e1aecc260dac0ba6381a9e5f5f6cff29 /src
parent7999b0b96e3509c64c892085c28ef3854a3a9a8e (diff)
Parsing.GridTable: remove use of unsafe function `last`
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Parsing/GridTable.hs5
1 files changed, 3 insertions, 2 deletions
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