aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Parsing.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2021-03-11 15:49:27 -0800
committerJohn MacFarlane <[email protected]>2021-03-13 15:05:37 -0800
commit8be95ad8e5150d5cab66c4abdf59baaf4670c6c8 (patch)
tree9655036efbaabda6a2a7802dc971c7fba5a987ca /src/Text/Pandoc/Parsing.hs
parent35b66a76718205c303f416bf0afc01c098e8a171 (diff)
Use custom Prelude based on relude.relude
The Prelude now longer exports partial functions, so a large number of uses of these functions in the code base have been rewritten. A .ghci file has been added; this is necessary for ghci to work properly with the custom Prelude. Currently there are lots of compiler warnings. We should either fix these or go to using a custom Prelude that changes less than relude.
Diffstat (limited to 'src/Text/Pandoc/Parsing.hs')
-rw-r--r--src/Text/Pandoc/Parsing.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index 8d3799c3e..7f2cd1ba1 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -773,7 +773,10 @@ withRaw parser = do
let raw = case inplines of
[] -> ""
[l] -> T.take (c2 - c1) l
- ls -> T.unlines (init ls) <> T.take (c2 - 1) (last ls)
+ _ -> fromMaybe "" $
+ viaNonEmpty (\ls ->
+ T.unlines (init ls) <> T.take (c2 - 1) (last ls))
+ inplines
return (result, raw)
-- | Parses backslash, then applies character parser.
@@ -990,7 +993,7 @@ widthsFromIndices :: Int -- Number of columns on terminal
-> [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' (fromMaybe 0 $ viaNonEmpty last indices)
lengths' = zipWith (-) indices (0:indices)
lengths = reverse $
case reverse lengths' of
@@ -1006,8 +1009,8 @@ widthsFromIndices numColumns' indices =
quotient = if totLength > numColumns
then fromIntegral totLength
else fromIntegral numColumns
- fracs = map (\l -> fromIntegral l / quotient) lengths in
- tail fracs
+ fracs = map (\l -> fromIntegral l / quotient) lengths
+ in fromMaybe [] $ viaNonEmpty tail fracs
---
@@ -1034,8 +1037,9 @@ gridTableWith' blocks headless =
(gridTableSep '-') gridTableFooter
gridTableSplitLine :: [Int] -> Text -> [Text]
-gridTableSplitLine indices line = map removeFinalBar $ tail $
- splitTextByIndices (init indices) $ trimr line
+gridTableSplitLine indices line = maybe [] (map removeFinalBar) $
+ viaNonEmpty tail $
+ splitTextByIndices (fromMaybe [] $ viaNonEmpty init indices) $ trimr line
gridPart :: Stream s m Char => Char -> ParserT s st m ((Int, Int), Alignment)
gridPart ch = do