git.iko.soy/typeable/pandoc
on master help sign in
Add custom prelude.

This version keeps head, tail, etc. but issues warnings if you use them, and exports safe alternatives.

commit886c677b8ea5cdeca83ab104e5fad9f2dc058f6f authorJohn MacFarlane <jgm@berkeley.edu> dateSun 14 Mar 2021, 09:53 (6 years ago) parent2b83363
27 files changed+386−85
.ghci+4 pandoc.cabal+4−7 prelude/Prelude.hs+318−11 src/Text/Pandoc/Parsing.hs+1−1 src/Text/Pandoc/Readers/DocBook.hs+1−1 src/Text/Pandoc/Readers/Docx/Lists.hs+1−2 src/Text/Pandoc/Readers/Docx/Parse.hs+1−1 src/Text/Pandoc/Readers/DokuWiki.hs+2−2 src/Text/Pandoc/Readers/HTML.hs+7−3 src/Text/Pandoc/Readers/JATS.hs+1−1 src/Text/Pandoc/Readers/LaTeX.hs+3−5 src/Text/Pandoc/Readers/Markdown.hs+4−4 src/Text/Pandoc/Readers/MediaWiki.hs+3−3 src/Text/Pandoc/Readers/Muse.hs+2−2 src/Text/Pandoc/Readers/Odt/Generic/Utils.hs−4 src/Text/Pandoc/Readers/Org/Blocks.hs+1−1 src/Text/Pandoc/Readers/RST.hs+3−3 src/Text/Pandoc/Readers/TWiki.hs+2−2 src/Text/Pandoc/Readers/Textile.hs+2−2 src/Text/Pandoc/Readers/TikiWiki.hs+2−3 src/Text/Pandoc/Readers/Txt2Tags.hs+5−7 src/Text/Pandoc/Readers/Vimwiki.hs+2−2 src/Text/Pandoc/Writers/AsciiDoc.hs+5−5 src/Text/Pandoc/Writers/Docx.hs+1−1 src/Text/Pandoc/Writers/HTML.hs+6−6 src/Text/Pandoc/Writers/Markdown.hs+1−1 src/Text/Pandoc/Writers/OpenDocument.hs+4−5
.ghcinew file+4
@@ -0,0 +1,4 @@
1+:load prelude/Prelude.hs
2+import Prelude
3+:set -XImplicitPrelude
4+:set -XOverloadedStrings
pandoc.cabal+4−7
@@ -398,16 +398,14 @@ flag trypandoc
398398
399399common common-options
400400 default-language: Haskell2010
401− build-depends: base >= 4.9 && < 5
401+ build-depends: base >= 4.10 && < 5, safe
402402 ghc-options: -Wall -fno-warn-unused-do-bind
403403 -Wincomplete-record-updates
404404 -Wnoncanonical-monad-instances
405405
406− if impl(ghc < 8.4)
407− hs-source-dirs: prelude
408− other-modules: Prelude
409− build-depends: base-compat >= 0.9
410− other-extensions: NoImplicitPrelude
406+ other-extensions: NoImplicitPrelude
407+ hs-source-dirs: prelude
408+ other-modules: Prelude
411409
412410 if os(windows)
413411 cpp-options: -D_WINDOWS
@@ -428,7 +426,6 @@ common common-executable
428426 build-depends: pandoc
429427 ghc-options: -rtsopts -with-rtsopts=-K16m -threaded
430428
431−
432429library
433430 import: common-options
434431 build-depends: Glob >= 0.7 && < 0.11,
prelude/Prelude.hs+318−11
@@ -1,15 +1,322 @@
1+{-# LANGUAGE PackageImports #-}
12{-# LANGUAGE NoImplicitPrelude #-}
23
3−-- The intent is that this Prelude provide the API of
4−-- the base 4.11 Prelude in a way that is portable for
5−-- all base versions.
4+-- Amplified Prelude for pandoc
5+-- comment -- pandoc indicates pandoc additions
66
7−module Prelude
8−(
9− module Prelude.Compat
10−, Semigroup(..)
11−)
12−where
7+module Prelude (
8+
9+ -- * Standard types, classes and related functions
10+
11+ -- ** Bool
12+ Bool(False, True),
13+ (&&), (||), not, otherwise,
14+
15+ -- ** Maybe
16+ Maybe(Nothing, Just),
17+ maybe,
18+ isJust, isNothing, fromMaybe, -- pandoc
19+ listToMaybe, maybeToList, catMaybes, mapMaybe, -- pandoc
20+
21+ -- ** Either
22+ Either(Left, Right),
23+ either,
24+ lefts, rights, isLeft, isRight, -- pandoc
25+ fromLeft, fromRight, partitionEithers, -- pandoc
26+
27+ -- ** Ord
28+ Ordering(LT, EQ, GT),
29+ Ord(compare, (<), (<=), (>=), (>), max, min),
30+ comparing, -- pandoc
31+ Down, -- pandoc
32+
33+ -- ** Char and String
34+ Char, String,
35+ lines, words, unlines, unwords,
36+
37+ -- *** Tuples
38+ fst, snd, curry, uncurry,
39+ swap, -- pandoc
40+
41+ -- ** Basic type classes
42+ Eq((==), (/=)),
43+ Enum(succ, pred, toEnum, fromEnum, enumFrom, enumFromThen,
44+ enumFromTo, enumFromThenTo),
45+ Bounded(minBound, maxBound),
46+
47+ -- ** Numbers
48+
49+ -- *** Numeric types
50+ Int, Integer, Float, Double,
51+ Rational, Word,
52+
53+ -- *** Numeric type classes
54+ Num((+), (-), (*), negate, abs, signum, fromInteger),
55+ Real(toRational),
56+ Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
57+ Fractional((/), recip, fromRational),
58+ Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
59+ asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
60+ RealFrac(properFraction, truncate, round, ceiling, floor),
61+ RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
62+ encodeFloat, exponent, significand, scaleFloat, isNaN,
63+ isInfinite, isDenormalized, isIEEE, isNegativeZero, atan2),
64+
65+ -- *** Numeric functions
66+ subtract, even, odd, gcd, lcm, (^), (^^),
67+ fromIntegral, realToFrac,
68+
69+ -- ** Semigroups and Monoids
70+ Semigroup((<>)),
71+ Monoid(mempty, mappend, mconcat),
72+
73+ -- ** Monads and functors
74+ Functor(fmap, (<$)), (<$>),
75+ Applicative(pure, (<*>), (*>), (<*)),
76+ Monad((>>=), (>>), return),
77+ MonadPlus (mzero, mplus), msum, -- pandoc
78+ MonadFail(fail),
79+ mapM_, sequence_, (=<<),
80+ forM_, (>=>), (<=<), forever, void, -- pandoc
81+ filterM, mfilter, join, zipWithM, zipWithM_, foldM, foldM_, -- pandoc
82+ replicateM, replicateM_, guard, when, unless, -- pandoc
83+ liftM, liftM2, liftM3, liftM4, liftM5, ap, (<$!>), -- pandoc
84+
85+ -- ** Folds and traversals
86+ Foldable.Foldable(elem, -- :: (Foldable t, Eq a) => a -> t a -> Bool
87+ fold, -- :: Monoid m => t m -> m -- pandoc
88+ foldMap, -- :: Monoid m => (a -> m) -> t a -> m
89+ foldr, -- :: (a -> b -> b) -> b -> t a -> b
90+ foldr', -- :: (a -> b -> b) -> b -> t a -> b -- pandoc
91+ -- foldl, -- :: (b -> a -> b) -> b -> t a -> b -- pandoc
92+ foldl' -- :: (b -> a -> b) -> b -> t a -> b -- pandoc
93+ -- foldr1, -- :: (a -> a -> a) -> t a -> a -- pandoc
94+ -- foldl1, -- :: (a -> a -> a) -> t a -> a -- pandoc
95+ -- maximum, -- :: (Foldable t, Ord a) => t a -> a
96+ -- minimum -- :: (Foldable t, Ord a) => t a -> a
97+ -- product, -- :: (Foldable t, Nu => t a -> a -- pandoc
98+ -- sum -- :: Num a => t a -> a -- pandoc
99+ -- toList -- :: Foldable t => t a -> [a] -- pandoc
100+ ),
101+ maximum, minimum, maximumMay, minimumMay, -- pandoc
102+ sum', product', -- pandoc
103+
104+ Traversable.Traversable(traverse, sequenceA, mapM, sequence),
105+ Traversable.for, Traversable.forM, -- pandoc
106+ Traversable.mapAccumL, Traversable.mapAccumR, -- pandoc
107+
108+ -- ** Miscellaneous functions
109+ id, const, (.), flip, ($), until,
110+ asTypeOf, error, errorWithoutStackTrace, undefined,
111+ seq, ($!),
112+
113+ -- * List operations
114+ List.map, (List.++), List.filter,
115+ -- List.head, List.last, List.tail, List.init, (List.!!), -- pandoc
116+ head, last, tail, init, (!!), -- pandoc
117+ headMay, lastMay, tailMay, initMay, (!!?), -- pandoc
118+ Foldable.null, Foldable.length,
119+ List.reverse,
120+ -- *** Special folds
121+ Foldable.and, Foldable.or, Foldable.any, Foldable.all,
122+ Foldable.concat, Foldable.concatMap,
123+ -- ** Building lists
124+ -- *** Scans
125+ List.scanl,
126+ -- List.scanl1, -- pandoc
127+ List.scanr,
128+ -- List.scanr1, -- pandoc
129+ -- *** Infinite lists
130+ List.iterate, List.repeat, List.replicate, List.cycle,
131+ -- ** Sublists
132+ List.take, List.drop,
133+ List.takeWhile, List.dropWhile,
134+ List.span, List.break,
135+ List.splitAt,
136+ List.isPrefixOf, List.isSuffixOf, List.isInfixOf, -- pandoc
137+ -- ** Searching lists
138+ Foldable.notElem,
139+ List.lookup,
140+ -- ** Zipping and unzipping lists
141+ List.zip, List.zip3,
142+ List.zipWith, List.zipWith3,
143+ List.unzip, List.unzip3,
144+
145+ -- * Converting to and from @String@
146+ -- ** Converting to @String@
147+ ShowS,
148+ Show(showsPrec, showList, show),
149+ shows,
150+ showChar, showString, showParen,
151+ -- ** Converting from @String@
152+ ReadS,
153+ Read(readsPrec, readList),
154+ reads,
155+ readParen,
156+ read, -- pandoc
157+ readMay, -- pandoc
158+ lex,
159+
160+ -- * Basic Input and output
161+ IO,
162+ -- ** Simple I\/O operations
163+ -- All I/O functions defined here are character oriented. The
164+ -- treatment of the newline character will vary on different systems.
165+ -- For example, two characters of input, return and linefeed, may
166+ -- read as a single newline character. These functions cannot be
167+ -- used portably for binary I/O.
168+ -- *** Output functions
169+ putChar,
170+ putStr, putStrLn, print,
171+ -- *** Input functions
172+ getChar,
173+ getLine, getContents, interact,
174+ -- *** Files
175+ FilePath,
176+ readFile, writeFile, appendFile, readIO, readLn,
177+ -- ** Exception handling in the I\/O monad
178+ IOError, ioError, userError,
179+
180+ -- ** Debugging
181+ traceShowId, traceShowIdWith, traceIO, trace, traceId, -- pandoc
182+ traceShow, traceM, traceShowM, traceStack, -- pandoc
183+ traceEvent, traceEventIO, traceMarker, traceMarkerIO, -- pandoc
184+
185+ -- ** Generics
186+ module Data.Data, -- pandoc
187+ module Data.Typeable -- pandoc
188+
189+ ) where
190+
191+import "base" Prelude hiding (read, head, last, init, tail, (!!),
192+ maximum, minimum)
193+import qualified "base" Prelude as StandardPrelude
194+import Data.Maybe
195+import Data.Char hiding (Char)
196+import Data.Either
197+import Data.Ord
198+import qualified Data.List as List
199+import qualified Data.Foldable as Foldable
200+import qualified Data.Traversable as Traversable
201+import Data.Tuple (swap)
202+import Control.Monad
203+import qualified Debug.Trace as Trace
204+import Data.Data
205+import Data.Typeable
206+import qualified Data.String as String
207+import Safe (atMay, headMay, lastMay, initMay, tailMay, readMay)
208+-- TODO
209+
210+-- replacements for sum, product
211+-- nonempty?
212+-- generics?
213+-- applicative/alternative?
214+-- exceptions?
215+
216+{-# WARNING head "head is a partial function: use headMay instead." #-}
217+head :: [a] -> a
218+head = List.head
219+
220+{-# WARNING last "last is a partial function: use lastMay instead." #-}
221+last :: [a] -> a
222+last = List.last
223+
224+{-# WARNING init "init is a partial function: use initMay instead." #-}
225+init :: [a] -> [a]
226+init = List.init
227+
228+{-# WARNING tail "tail is a partial function: use tailMay instead." #-}
229+tail :: [a] -> [a]
230+tail = List.tail
231+
232+{-# WARNING (!!) "(!!) is a partial function: use (!!?) instead." #-}
233+(!!) :: [a] -> Int -> a
234+(!!) = (List.!!)
235+
236+{-# WARNING maximum "maximum is a partial function: use maximumMay instead." #-}
237+maximum :: (Foldable t, Ord a) => t a -> a
238+maximum = Foldable.maximum
239+
240+{-# WARNING minimum "minimum is a partial function: use minimumMay instead." #-}
241+minimum :: (Foldable t, Ord a) => t a -> a
242+minimum = Foldable.minimum
243+
244+(!!?) :: [a] -> Int -> Maybe a
245+(!!?) = Safe.atMay
246+
247+-- borrowed from Safe.Util:
248+liftMay :: (a -> Bool) -> (a -> b) -> (a -> Maybe b)
249+liftMay test func val
250+ | test val = Nothing
251+ | otherwise = Just $ func val
252+
253+maximumMay :: (Foldable t, Ord a) => t a -> Maybe a
254+maximumMay = liftMay Foldable.null Foldable.maximum
255+
256+minimumMay :: (Foldable t, Ord a) => t a -> Maybe a
257+minimumMay = liftMay Foldable.null Foldable.minimum
258+
259+{-# WARNING read "read is a partial function: use readMay instead." #-}
260+read :: Read a => String -> a
261+read = StandardPrelude.read
262+
263+-- | Strict sum.
264+sum' :: (Foldable t, Num a) => t a -> a
265+sum' x = Foldable.foldl' (+) 0 x
266+
267+-- | Strict product.
268+product' :: (Foldable t, Num a) => t a -> a
269+product' x = Foldable.foldl' (*) 0 x
270+
271+{-# WARNING traceShowId "traceShowId left in code" #-}
272+traceShowId :: Show a => a -> a
273+traceShowId = Trace.traceShowId
274+
275+{-# WARNING traceShowIdWith "traceShowIdWith left in code" #-}
276+traceShowIdWith :: Show a => (String -> String) -> a -> a
277+traceShowIdWith f x = Trace.trace (f (show x)) x
278+
279+{-# WARNING traceIO "traceIO left in code" #-}
280+traceIO :: String -> IO ()
281+traceIO = Trace.traceIO
282+
283+{-# WARNING trace "trace left in code" #-}
284+trace :: String -> a -> a
285+trace = Trace.trace
286+
287+{-# WARNING traceId "traceId left in code" #-}
288+traceId :: String -> String
289+traceId = Trace.traceId
290+
291+{-# WARNING traceShow "traceShow left in code" #-}
292+traceShow :: Show a => a -> b -> b
293+traceShow = Trace.traceShow
294+
295+{-# WARNING traceM "traceM left in code" #-}
296+traceM :: Applicative f => String -> f ()
297+traceM = Trace.traceM
298+
299+{-# WARNING traceShowM "traceShowM left in code" #-}
300+traceShowM :: (Show a, Applicative f) => a -> f ()
301+traceShowM = Trace.traceShowM
302+
303+{-# WARNING traceStack "traceStack left in code" #-}
304+traceStack :: String -> a -> a
305+traceStack = Trace.traceStack
306+
307+{-# WARNING traceEvent "traceEvent left in code" #-}
308+traceEvent :: String -> a -> a
309+traceEvent = Trace.traceEvent
310+
311+{-# WARNING traceEventIO "traceIO left in code" #-}
312+traceEventIO :: String -> IO ()
313+traceEventIO = Trace.traceEventIO
314+
315+{-# WARNING traceMarker "traceMarker left in code" #-}
316+traceMarker :: String -> a -> a
317+traceMarker = Trace.traceMarker
318+
319+{-# WARNING traceMarkerIO "traceMarkerIO left in code" #-}
320+traceMarkerIO :: String -> IO ()
321+traceMarkerIO = Trace.traceMarkerIO
13322
14−import Prelude.Compat
15−import Data.Semigroup (Semigroup(..)) -- includes (<>)
src/Text/Pandoc/Parsing.hs+1−1
@@ -1002,7 +1002,7 @@ widthsFromIndices numColumns' indices =
10021002 (x:y:zs) -> if x < y && y - x <= 2
10031003 then y:y:zs
10041004 else x:y:zs
1005− totLength = sum lengths
1005+ totLength = sum' lengths
10061006 quotient = if totLength > numColumns
10071007 then fromIntegral totLength
10081008 else fromIntegral numColumns
src/Text/Pandoc/Readers/DocBook.hs+1−1
@@ -966,7 +966,7 @@ parseBlock (Elem e) =
966966 [] -> replicate numrows ColWidthDefault
967967 cs -> let ws = map toWidth cs
968968 in case sequence ws of
969− Just ws' -> let colTot = sum ws'
969+ Just ws' -> let colTot = sum' ws'
970970 scale
971971 | textWidth == 1.0 = (/ colTot)
972972 | otherwise = (* (textWidth / colTot) )
src/Text/Pandoc/Readers/Docx/Lists.hs+1−2
@@ -17,8 +17,7 @@ module Text.Pandoc.Readers.Docx.Lists ( blocksToBullets
1717 , listParagraphStyles
1818 ) where
1919
20−import Data.List
21−import Data.Maybe
20+import Data.List (delete, intersect, (\\))
2221import Data.String (fromString)
2322import qualified Data.Text as T
2423import Text.Pandoc.Generic (bottomUp)
src/Text/Pandoc/Readers/Docx/Parse.hs+1−1
@@ -60,8 +60,8 @@ import Control.Monad.State.Strict
6060import Data.Bits ((.|.))
6161import qualified Data.ByteString.Lazy as B
6262import Data.Char (chr, ord, readLitChar)
63−import Data.List
6463import qualified Data.Map as M
64+import Data.List (find)
6565import qualified Data.Text as T
6666import Data.Text (Text)
6767import Data.Maybe
src/Text/Pandoc/Readers/DokuWiki.hs+2−2
@@ -24,7 +24,7 @@ import Data.Maybe (fromMaybe, catMaybes)
2424import Data.Text (Text)
2525import qualified Data.Text as T
2626import qualified Text.Pandoc.Builder as B
27−import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
27+import Text.Pandoc.Class as P (PandocMonad (..))
2828import Text.Pandoc.Definition
2929import Text.Pandoc.Error (PandocError (PandocParsecError))
3030import Text.Pandoc.Options
@@ -388,7 +388,7 @@ block = do
388388 <|> blockElements
389389 <|> para
390390 skipMany blankline
391− trace (T.take 60 $ tshow $ B.toList res)
391+ P.trace (T.take 60 $ tshow $ B.toList res)
392392 return res
393393
394394blockElements :: PandocMonad m => DWParser m B.Blocks
src/Text/Pandoc/Readers/HTML.hs+7−3
@@ -43,7 +43,7 @@ import Text.HTML.TagSoup
4343import Text.HTML.TagSoup.Match
4444import Text.Pandoc.Builder (Blocks, Inlines, trimInlines)
4545import qualified Text.Pandoc.Builder as B
46−import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
46+import Text.Pandoc.Class as P (PandocMonad (..))
4747import Text.Pandoc.CSS (pickStyleAttrProps)
4848import qualified Text.Pandoc.UTF8 as UTF8
4949import Text.Pandoc.Definition
@@ -66,6 +66,7 @@ import Text.Pandoc.Shared (
6666import Text.Pandoc.Walk
6767import Text.Parsec.Error
6868import Text.TeXMath (readMathML, writeTeX)
69+import Data.List.NonEmpty (nonEmpty, NonEmpty(..))
6970
7071-- | Convert HTML-formatted string to 'Pandoc' document.
7172readHtml :: PandocMonad m
@@ -214,7 +215,7 @@ block = ((do
214215 -> eSwitch B.para block
215216 _ -> mzero
216217 _ -> mzero) <|> pPlain <|> pRawHtmlBlock) >>= \res ->
217− res <$ trace (T.take 60 $ tshow $ B.toList res)
218+ res <$ P.trace (T.take 60 $ tshow $ B.toList res)
218219
219220namespaces :: PandocMonad m => [(Text, TagParser m Inlines)]
220221namespaces = [(mathMLNamespace, pMath True)]
@@ -360,7 +361,10 @@ pDefListItem = try $ do
360361 terms <- many1 (try $ skipMany nonItem >> pInTags "dt" inline)
361362 defs <- many1 (try $ skipMany nonItem >> pInTags "dd" block)
362363 skipMany nonItem
363− let term = foldl1 (\x y -> x <> B.linebreak <> y) $ map trimInlines terms
364+ let term = case nonEmpty (map trimInlines terms) of
365+ Just (z :| zs) ->
366+ foldl' (\x y -> x <> B.linebreak <> y) z zs
367+ Nothing -> mempty
364368 return (term, map (fixPlains True) defs)
365369
366370fixPlains :: Bool -> Blocks -> Blocks
src/Text/Pandoc/Readers/JATS.hs+1−1
@@ -262,7 +262,7 @@ parseBlock (Elem e) =
262262 [] -> replicate numrows ColWidthDefault
263263 cs -> let ws = map toWidth cs
264264 in case sequence ws of
265− Just ws' -> let tot = sum ws'
265+ Just ws' -> let tot = sum' ws'
266266 in ColWidth . (/ tot) <$> ws'
267267 Nothing -> replicate numrows ColWidthDefault
268268 let toRow = Row nullAttr . map simpleCell
src/Text/Pandoc/Readers/LaTeX.hs+3−5
@@ -36,10 +36,8 @@ import qualified Data.Text as T
3636import System.FilePath (addExtension, replaceExtension, takeExtension)
3737import Text.Pandoc.BCP47 (renderLang)
3838import Text.Pandoc.Builder as B
39−import Text.Pandoc.Class.PandocPure (PandocPure)
40−import Text.Pandoc.Class.PandocMonad (PandocMonad (..), getResourcePath,
41− readFileFromDirs, report,
42− setResourcePath)
39+import Text.Pandoc.Class as P (PandocPure, PandocMonad (..), getResourcePath,
40+ readFileFromDirs, report, setResourcePath)
4341import Text.Pandoc.Error (PandocError (PandocParseError, PandocParsecError))
4442import Text.Pandoc.Highlighting (languagesByExtension)
4543import Text.Pandoc.ImageSize (numUnit, showFl)
@@ -1255,7 +1253,7 @@ block = do
12551253 _ -> mzero)
12561254 <|> paragraph
12571255 <|> grouped block
1258− trace (T.take 60 $ tshow $ B.toList res)
1256+ P.trace (T.take 60 $ tshow $ B.toList res)
12591257 return res
12601258
12611259blocks :: PandocMonad m => LP m Blocks
src/Text/Pandoc/Readers/Markdown.hs+4−4
@@ -33,7 +33,7 @@ import System.FilePath (addExtension, takeExtension)
3333import Text.HTML.TagSoup hiding (Row)
3434import Text.Pandoc.Builder (Blocks, Inlines)
3535import qualified Text.Pandoc.Builder as B
36−import Text.Pandoc.Class.PandocMonad (PandocMonad (..), report)
36+import Text.Pandoc.Class as P (PandocMonad (..), report)
3737import Text.Pandoc.Definition as Pandoc
3838import Text.Pandoc.Emoji (emojiToInline)
3939import Text.Pandoc.Error
@@ -476,7 +476,7 @@ block = do
476476 , para
477477 , plain
478478 ] <?> "block"
479− trace (T.take 60 $ tshow $ B.toList $ runF res defaultParserState)
479+ P.trace (T.take 60 $ tshow $ B.toList $ runF res defaultParserState)
480480 return res
481481
482482--
@@ -1368,7 +1368,7 @@ pipeTable = try $ do
13681368 numColumns <- getOption readerColumns
13691369 let widths = if maxlength > numColumns
13701370 then map (\len ->
1371− fromIntegral len / fromIntegral (sum seplengths))
1371+ fromIntegral len / fromIntegral (sum' seplengths))
13721372 seplengths
13731373 else replicate (length aligns) 0.0
13741374 return (aligns, widths, toHeaderRow <$> heads', map toRow <$> sequence lines'')
@@ -1460,7 +1460,7 @@ table = try $ do
14601460 Nothing -> option (return mempty) tableCaption
14611461 Just c -> return c
14621462 -- renormalize widths if greater than 100%:
1463− let totalWidth = sum widths
1463+ let totalWidth = sum' widths
14641464 let widths' = if totalWidth < 1
14651465 then widths
14661466 else map (/ totalWidth) widths
src/Text/Pandoc/Readers/MediaWiki.hs+3−3
@@ -30,7 +30,7 @@ import qualified Data.Text as T
3030import Text.HTML.TagSoup
3131import Text.Pandoc.Builder (Blocks, Inlines, trimInlines)
3232import qualified Text.Pandoc.Builder as B
33−import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
33+import Text.Pandoc.Class as P (PandocMonad (..))
3434import Text.Pandoc.Definition
3535import Text.Pandoc.Logging
3636import Text.Pandoc.Options
@@ -192,7 +192,7 @@ block = do
192192 <|> blockTag
193193 <|> (B.rawBlock "mediawiki" <$> template)
194194 <|> para
195− trace (T.take 60 $ tshow $ B.toList res)
195+ P.trace (T.take 60 $ tshow $ B.toList res)
196196 return res
197197
198198para :: PandocMonad m => MWParser m Blocks
@@ -218,7 +218,7 @@ table = do
218218 hasheader <- option False $ True <$ lookAhead (skipSpaces *> char '!')
219219 (cellspecs',hdr) <- unzip <$> tableRow
220220 let widths = map ((tableWidth *) . snd) cellspecs'
221− let restwidth = tableWidth - sum widths
221+ let restwidth = tableWidth - sum' widths
222222 let zerocols = length $ filter (==0.0) widths
223223 let defaultwidth = if zerocols == 0 || zerocols == length widths
224224 then ColWidthDefault
src/Text/Pandoc/Readers/Muse.hs+2−2
@@ -31,7 +31,7 @@ import Data.Text (Text)
3131import qualified Data.Text as T
3232import Text.Pandoc.Builder (Blocks, Inlines, underline)
3333import qualified Text.Pandoc.Builder as B
34−import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
34+import Text.Pandoc.Class as P (PandocMonad (..))
3535import Text.Pandoc.Definition
3636import Text.Pandoc.Error (PandocError (PandocParsecError))
3737import Text.Pandoc.Logging
@@ -293,7 +293,7 @@ listItemContentsUntil col pre end = p
293293parseBlock :: PandocMonad m => MuseParser m (F Blocks)
294294parseBlock = do
295295 res <- blockElements <|> para
296− trace (T.take 60 $ tshow $ B.toList $ runF res def)
296+ P.trace (T.take 60 $ tshow $ B.toList $ runF res def)
297297 return res
298298 where para = fst <$> paraUntil (try (eof <|> void (lookAhead blockElements)))
299299
src/Text/Pandoc/Readers/Odt/Generic/Utils.hs−4
@@ -16,7 +16,6 @@ module Text.Pandoc.Readers.Odt.Generic.Utils
1616, uncurry4
1717, uncurry5
1818, uncurry6
19−, swap
2019, reverseComposition
2120, tryToRead
2221, Lookupable(..)
@@ -104,9 +103,6 @@ uncurry4 fun (a,b,c,d ) = fun a b c d
104103uncurry5 fun (a,b,c,d,e ) = fun a b c d e
105104uncurry6 fun (a,b,c,d,e,f ) = fun a b c d e f
106105
107−swap :: (a,b) -> (b,a)
108−swap (a,b) = (b,a)
109−
110106-- | A version of "Data.List.find" that uses a converter to a Maybe instance.
111107-- The returned value is the first which the converter returns in a 'Just'
112108-- wrapper.
src/Text/Pandoc/Readers/Org/Blocks.hs+1−1
@@ -637,7 +637,7 @@ orgToPandocTable :: OrgTable
637637 -> Blocks
638638orgToPandocTable (OrgTable colProps heads lns) caption =
639639 let totalWidth = if any (isJust . columnRelWidth) colProps
640− then Just . sum $ map (fromMaybe 1 . columnRelWidth) colProps
640+ then Just . sum' $ map (fromMaybe 1 . columnRelWidth) colProps
641641 else Nothing
642642 in B.table (B.simpleCaption $ B.plain caption)
643643 (map (convertColProp totalWidth) colProps)
src/Text/Pandoc/Readers/RST.hs+3−3
@@ -799,7 +799,7 @@ tableDirective top fields body = do
799799 _ -> return mempty
800800 where
801801 -- only valid on the very first row of a table section
802− rowLength (Row _ rb) = sum $ cellLength <$> rb
802+ rowLength (Row _ rb) = sum' $ cellLength <$> rb
803803 cellLength (Cell _ _ _ (ColSpan w) _) = max 1 w
804804 strictPos w
805805 | w > 0 = ColWidth w
@@ -839,7 +839,7 @@ listTableDirective top fields body = do
839839 takeRows _ = []
840840 takeCells [BulletList cells] = map B.fromList cells
841841 takeCells _ = []
842− normWidths ws = strictPos . (/ max 1 (sum ws)) <$> ws
842+ normWidths ws = strictPos . (/ max 1 (sum' ws)) <$> ws
843843 strictPos w
844844 | w > 0 = ColWidth w
845845 | otherwise = ColWidthDefault
@@ -904,7 +904,7 @@ csvTableDirective top fields rawcsv = do
904904 let strictPos w
905905 | w > 0 = ColWidth w
906906 | otherwise = ColWidthDefault
907− let normWidths ws = strictPos . (/ max 1 (sum ws)) <$> ws
907+ let normWidths ws = strictPos . (/ max 1 (sum' ws)) <$> ws
908908 let widths =
909909 case trim <$> lookup "widths" fields of
910910 Just "auto" -> replicate numOfCols ColWidthDefault
src/Text/Pandoc/Readers/TWiki.hs+2−2
@@ -23,7 +23,7 @@ import Data.Text (Text)
2323import qualified Data.Text as T
2424import Text.HTML.TagSoup
2525import qualified Text.Pandoc.Builder as B
26−import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
26+import Text.Pandoc.Class as P (PandocMonad (..))
2727import Text.Pandoc.Definition
2828import Text.Pandoc.Options
2929import Text.Pandoc.Parsing hiding (enclosed, nested)
@@ -116,7 +116,7 @@ block = do
116116 <|> blockElements
117117 <|> para
118118 skipMany blankline
119− trace (T.take 60 $ tshow $ B.toList res)
119+ P.trace (T.take 60 $ tshow $ B.toList res)
120120 return res
121121
122122blockElements :: PandocMonad m => TWParser m B.Blocks
src/Text/Pandoc/Readers/Textile.hs+2−2
@@ -45,7 +45,7 @@ import Text.HTML.TagSoup (Tag (..), fromAttrib)
4545import Text.HTML.TagSoup.Match
4646import Text.Pandoc.Builder (Blocks, Inlines, trimInlines)
4747import qualified Text.Pandoc.Builder as B
48−import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
48+import Text.Pandoc.Class as P (PandocMonad (..))
4949import Text.Pandoc.CSS
5050import Text.Pandoc.Definition
5151import Text.Pandoc.Options
@@ -123,7 +123,7 @@ blockParsers = [ codeBlock
123123block :: PandocMonad m => ParserT Text ParserState m Blocks
124124block = do
125125 res <- choice blockParsers <?> "block"
126− trace (T.take 60 $ tshow $ B.toList res)
126+ P.trace (T.take 60 $ tshow $ B.toList res)
127127 return res
128128
129129commentBlock :: PandocMonad m => ParserT Text ParserState m Blocks
src/Text/Pandoc/Readers/TikiWiki.hs+2−3
@@ -24,8 +24,7 @@ import Data.Maybe (fromMaybe)
2424import Data.Text (Text)
2525import qualified Data.Text as T
2626import qualified Text.Pandoc.Builder as B
27−import Text.Pandoc.Class.CommonState (CommonState (..))
28−import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
27+import Text.Pandoc.Class as P (CommonState (..), PandocMonad (..))
2928import Text.Pandoc.Definition
3029import Text.Pandoc.Logging (Verbosity (..))
3130import Text.Pandoc.Options
@@ -87,7 +86,7 @@ block = do
8786 <|> para
8887 skipMany blankline
8988 when (verbosity >= INFO) $
90− trace (T.pack $ printf "line %d: %s" (sourceLine pos) (take 60 $ show $ B.toList res))
89+ P.trace (T.pack $ printf "line %d: %s" (sourceLine pos) (take 60 $ show $ B.toList res))
9190 return res
9291
9392blockElements :: PandocMonad m => TikiWikiParser m B.Blocks
src/Text/Pandoc/Readers/Txt2Tags.hs+5−7
@@ -31,7 +31,8 @@ import Data.Time (defaultTimeLocale)
3131import Text.Pandoc.Definition
3232import Text.Pandoc.Options
3333import Text.Pandoc.Parsing hiding (space, spaces, uri)
34−import Text.Pandoc.Shared (compactify, compactifyDL, crFilter, escapeURI)
34+import Text.Pandoc.Shared (compactify, compactifyDL, crFilter, escapeURI,
35+ ordNub)
3536
3637type T2T = ParserT Text ParserState (Reader T2TMeta)
3738
@@ -261,7 +262,9 @@ table = try $ do
261262 rows <- many1 (many commentLine *> tableRow)
262263 let columns = transpose rows
263264 let ncolumns = length columns
264− let aligns = map (foldr1 findAlign . map fst) columns
265+ let aligns = map (\rs -> case ordNub $ map fst rs of
266+ [x] -> x
267+ _ -> AlignDefault) columns
265268 let rows' = map (map snd) rows
266269 let size = maximum (map length rows')
267270 let rowsPadded = map (pad size) rows'
@@ -278,11 +281,6 @@ pad :: (Monoid a) => Int -> [a] -> [a]
278281pad n xs = xs ++ replicate (n - length xs) mempty
279282
280283
281−findAlign :: Alignment -> Alignment -> Alignment
282−findAlign x y
283− | x == y = x
284− | otherwise = AlignDefault
285−
286284headerRow :: T2T [(Alignment, Blocks)]
287285headerRow = genericRow (string "||")
288286
src/Text/Pandoc/Readers/Vimwiki.hs+2−2
@@ -64,7 +64,7 @@ import qualified Text.Pandoc.Builder as B (blockQuote, bulletList, code,
6464 softbreak, space, spanWith, str,
6565 strikeout, strong, subscript,
6666 superscript)
67−import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
67+import Text.Pandoc.Class as P (PandocMonad (..))
6868import Text.Pandoc.Definition (Attr, Block (BulletList, OrderedList),
6969 Inline (Space), ListNumberDelim (..),
7070 ListNumberStyle (..), Pandoc (..),
@@ -129,7 +129,7 @@ block = do
129129 , definitionList
130130 , para
131131 ]
132− trace (T.take 60 $ tshow $ toList res)
132+ P.trace (T.take 60 $ tshow $ toList res)
133133 return res
134134
135135blockML :: PandocMonad m => VwParser m Blocks
src/Text/Pandoc/Writers/AsciiDoc.hs+5−5
@@ -210,17 +210,17 @@ blockToAsciiDoc opts block@(Table _ blkCapt specs thead tbody tfoot) = do
210210 let isSimple = all (== 0) widths
211211 let relativePercentWidths = if isSimple
212212 then widths
213− else map (/ sum widths) widths
213+ else map (/ sum' widths) widths
214214 let widths'' :: [Integer]
215215 widths'' = map (floor . (* 100)) relativePercentWidths
216− -- ensure that the widths sum to 100
216+ -- ensure that the widths sum' to 100
217217 let widths' = case widths'' of
218218 _ | isSimple -> widths''
219− (w:ws) | sum (w:ws) < 100
220− -> (100 - sum ws) : ws
219+ (w:ws) | sum' (w:ws) < 100
220+ -> (100 - sum' ws) : ws
221221 ws -> ws
222222 let totalwidth :: Integer
223− totalwidth = floor $ sum widths * 100
223+ totalwidth = floor $ sum' widths * 100
224224 let colspec al wi = (case al of
225225 AlignLeft -> "<"
226226 AlignCenter -> "^"
src/Text/Pandoc/Writers/Docx.hs+1−1
@@ -1031,7 +1031,7 @@ blockToOpenXML' opts (Table _ blkCapt specs thead tbody tfoot) = do
10311031 map mkcell cells
10321032 let textwidth = 7920 -- 5.5 in in twips, 1/20 pt
10331033 let fullrow = 5000 -- 100% specified in pct
1034− let (rowwidth :: Int) = round $ fullrow * sum widths
1034+ let (rowwidth :: Int) = round $ fullrow * sum' widths
10351035 let mkgridcol w = mknode "w:gridCol"
10361036 [("w:w", tshow (floor (textwidth * w) :: Integer))] ()
10371037 let hasHeader = not $ all null headers
src/Text/Pandoc/Writers/HTML.hs+6−6
@@ -375,12 +375,12 @@ prefixedId opts s =
375375 "" -> mempty
376376 _ -> A.id $ toValue $ writerIdentifierPrefix opts <> s
377377
378−toList :: PandocMonad m
378+toList' :: PandocMonad m
379379 => (Html -> Html)
380380 -> WriterOptions
381381 -> [Html]
382382 -> StateT WriterState m Html
383−toList listop opts items = do
383+toList' listop opts items = do
384384 slideVariant <- gets stSlideVariant
385385 return $
386386 if writerIncremental opts
@@ -391,15 +391,15 @@ toList listop opts items = do
391391
392392unordList :: PandocMonad m
393393 => WriterOptions -> [Html] -> StateT WriterState m Html
394−unordList opts = toList H.ul opts . toListItems opts
394+unordList opts = toList' H.ul opts . toListItems opts
395395
396396ordList :: PandocMonad m
397397 => WriterOptions -> [Html] -> StateT WriterState m Html
398−ordList opts = toList H.ol opts . toListItems opts
398+ordList opts = toList' H.ol opts . toListItems opts
399399
400400defList :: PandocMonad m
401401 => WriterOptions -> [Html] -> StateT WriterState m Html
402−defList opts items = toList H.dl opts (items ++ [nl opts])
402+defList opts items = toList' H.dl opts (items ++ [nl opts])
403403
404404isTaskListItem :: [Block] -> Bool
405405isTaskListItem (Plain (Str "☐":Space:_):_) = True
@@ -961,7 +961,7 @@ tableToHtml opts (Ann.Table attr caption colspecs thead tbodies tfoot) = do
961961 let colWidth = \case
962962 ColWidth d -> d
963963 ColWidthDefault -> 0
964− let totalWidth = sum . map (colWidth . snd) $ colspecs
964+ let totalWidth = sum' . map (colWidth . snd) $ colspecs
965965 let attr' = case lookup "style" kvs of
966966 Nothing | totalWidth < 1 && totalWidth > 0
967967 -> (ident,classes, ("style","width:" <>
src/Text/Pandoc/Writers/Markdown.hs+1−1
@@ -675,7 +675,7 @@ pandocTable opts multiline headless aligns widths rawHeaders rawRows = do
675675 let underline = mconcat $ intersperse (literal " ") $
676676 map (\width -> literal (T.replicate width "-")) widthsInChars
677677 let border
678− | multiline = literal (T.replicate (sum widthsInChars +
678+ | multiline = literal (T.replicate (sum' widthsInChars +
679679 length widthsInChars - 1) "-")
680680 | headless = underline
681681 | otherwise = empty
src/Text/Pandoc/Writers/OpenDocument.hs+4−5
@@ -97,9 +97,6 @@ defaultWriterState =
9797 , stIdentTypes = []
9898 }
9999
100−when :: Bool -> Doc Text -> Doc Text
101−when p a = if p then a else empty
102−
103100addTableStyle :: PandocMonad m => Doc Text -> OD m ()
104101addTableStyle i = modify $ \s -> s { stTableStyles = i : stTableStyles s }
105102
@@ -226,7 +223,9 @@ handleSpaces s = case T.uncons s of
226223 _ -> rm s
227224 where
228225 genTag = T.span (==' ') >>> tag . T.length *** rm >>> uncurry (<>)
229− tag n = when (n /= 0) $ selfClosingTag "text:s" [("text:c", tshow n)]
226+ tag n = if n /= 0
227+ then selfClosingTag "text:s" [("text:c", tshow n)]
228+ else mempty
230229 rm t = case T.uncons t of
231230 Just ( ' ',xs) -> char ' ' <> genTag xs
232231 Just ('\t',xs) -> selfClosingTag "text:tab" [] <> genTag xs
@@ -435,7 +434,7 @@ blockToOpenDocument o bs
435434 fromWidth (ColWidth w) | w > 0 = w
436435 fromWidth _ = 0
437436 widths = map fromWidth mwidths
438− textWidth = sum widths
437+ textWidth = sum' widths
439438 columnIds = zip genIds widths
440439 mkColumn n = selfClosingTag "table:table-column" [("table:style-name", name <> "." <> T.singleton (fst n))]
441440 columns = map mkColumn columnIds