git.iko.soy/typeable/pandoc
on master help sign in
Fix hlint suggestions, update hlint.yaml (#6680)

* Fix hlint suggestions, update hlint.yaml Most suggestions were redundant brackets. Some required LambdaCase. The .hlint.yaml file had a small typo, and didn't ignore camelCase suggestions in certain modules.

commitcae155b095e5182cc1b342b21f7430e40afe7ba8 authorChristian Despres <50160106+despresc@users.noreply.github.com> dateSun 13 Sep 2020, 10:48 (6 years ago) parent2109ded
69 files changed+291−321
.hlint.yaml+3−1 benchmark/weigh-pandoc.hs+1−1 src/Text/Pandoc/App/CommandLineOptions.hs+3−4 src/Text/Pandoc/Class/PandocMonad.hs+5−5 src/Text/Pandoc/Image.hs−1 src/Text/Pandoc/Logging.hs+2−2 src/Text/Pandoc/Lua/Marshaling/AST.hs+1−3 src/Text/Pandoc/Lua/Module/Utils.hs+2−3 src/Text/Pandoc/Options.hs+3−2 src/Text/Pandoc/PDF.hs+2−2 src/Text/Pandoc/Parsing.hs+7−9 src/Text/Pandoc/Readers/CSV.hs+1−1 src/Text/Pandoc/Readers/CommonMark.hs−1 src/Text/Pandoc/Readers/DocBook.hs+11−11 src/Text/Pandoc/Readers/Docx.hs+5−5 src/Text/Pandoc/Readers/Docx/Parse.hs+3−9 src/Text/Pandoc/Readers/DokuWiki.hs+1−1 src/Text/Pandoc/Readers/HTML.hs+1−1 src/Text/Pandoc/Readers/Haddock.hs+1−1 src/Text/Pandoc/Readers/JATS.hs+6−6 src/Text/Pandoc/Readers/LaTeX.hs+31−32 src/Text/Pandoc/Readers/LaTeX/Lang.hs+1−1 src/Text/Pandoc/Readers/LaTeX/Parsing.hs+6−8 src/Text/Pandoc/Readers/LaTeX/SIunitx.hs+3−3 src/Text/Pandoc/Readers/Man.hs+1−1 src/Text/Pandoc/Readers/Markdown.hs+6−6 src/Text/Pandoc/Readers/MediaWiki.hs+3−3 src/Text/Pandoc/Readers/Muse.hs+1−1 src/Text/Pandoc/Readers/Odt/ContentReader.hs+3−3 src/Text/Pandoc/Readers/Odt/Generic/XMLConverter.hs+2−1 src/Text/Pandoc/Readers/Org/Blocks.hs+11−12 src/Text/Pandoc/Readers/Org/ParserState.hs+1−1 src/Text/Pandoc/Readers/Org/Shared.hs+1−3 src/Text/Pandoc/Readers/RST.hs+4−4 src/Text/Pandoc/Readers/TWiki.hs+7−7 src/Text/Pandoc/Readers/Textile.hs+3−3 src/Text/Pandoc/Readers/Txt2Tags.hs+1−1 src/Text/Pandoc/Shared.hs+4−6 src/Text/Pandoc/Writers/CommonMark.hs−2 src/Text/Pandoc/Writers/ConTeXt.hs+3−3 src/Text/Pandoc/Writers/Docbook.hs+5−5 src/Text/Pandoc/Writers/Docx.hs+1−1 src/Text/Pandoc/Writers/EPUB.hs+12−14 src/Text/Pandoc/Writers/HTML.hs+1−2 src/Text/Pandoc/Writers/Haddock.hs+1−1 src/Text/Pandoc/Writers/JATS.hs+5−5 src/Text/Pandoc/Writers/LaTeX.hs+6−6 src/Text/Pandoc/Writers/Man.hs+2−2 src/Text/Pandoc/Writers/Markdown.hs+49−52 src/Text/Pandoc/Writers/Ms.hs+2−4 src/Text/Pandoc/Writers/ODT.hs+1−1 src/Text/Pandoc/Writers/OPML.hs+1−1 src/Text/Pandoc/Writers/OpenDocument.hs+1−1 src/Text/Pandoc/Writers/Powerpoint/Output.hs+14−15 src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+4−4 src/Text/Pandoc/Writers/RTF.hs+3−3 src/Text/Pandoc/Writers/TEI.hs+3−3 src/Text/Pandoc/Writers/XWiki.hs+1−1 src/Text/Pandoc/XML.hs+2−1 test/Tests/Helpers.hs+1−2 test/Tests/Old.hs+1−2 test/Tests/Readers/Docx.hs+1−1 test/Tests/Readers/Man.hs+1−1 test/Tests/Readers/Muse.hs+1−1 test/Tests/Readers/Org/Block/Table.hs+1−1 test/Tests/Readers/Org/Directive.hs+1−1 test/Tests/Readers/Txt2Tags.hs+1−1 test/Tests/Shared.hs+18−18 test/Tests/Writers/OOXML.hs+1−1
.hlint.yaml+3−1
@@ -74,8 +74,10 @@
7474- ignore:
7575 name: "Use camelCase"
7676 within:
77+ - Tests.Writers.Docbook
78+ - Tests.Writers.Native
7779 - Text.Pandoc.Extensions
78− - Text.Pandoc.Lua.Marshalling.Version
80+ - Text.Pandoc.Lua.Marshaling.Version
7981 - Text.Pandoc.Readers.Odt.ContentReader
8082 - Text.Pandoc.Readers.Odt.Namespaces
8183
benchmark/weigh-pandoc.hs+1−1
@@ -42,7 +42,7 @@ weighWriter :: Pandoc -> String -> (Pandoc -> Text) -> Weigh ()
4242weighWriter doc name writer = func (name ++ " writer") writer doc
4343
4444weighReader :: Pandoc -> Text -> (Text -> Pandoc) -> Weigh ()
45−weighReader doc name reader = do
45+weighReader doc name reader =
4646 case lookup name writers of
4747 Just (TextWriter writer) ->
4848 let inp = either (error . show) id $ runPure $ writer def{ writerWrapText = WrapAuto} doc
src/Text/Pandoc/App/CommandLineOptions.hs+3−4
@@ -1,4 +1,5 @@
11{-# LANGUAGE CPP #-}
2+{-# LANGUAGE LambdaCase #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34{-# LANGUAGE TupleSections #-}
45{-# LANGUAGE OverloadedStrings #-}
@@ -868,9 +869,7 @@ options =
868869 , Option "" ["print-highlight-style"]
869870 (ReqArg
870871 (\arg opt -> do
871− let write = case optOutputFile opt of
872− Just f -> B.writeFile f
873− Nothing -> B.putStr
872+ let write = maybe B.putStr B.writeFile $ optOutputFile opt
874873 sty <- runIOorExplode $ lookupHighlightStyle arg
875874 write $ encodePretty'
876875 defConfig{confIndent = Spaces 4
@@ -1017,7 +1016,7 @@ lookupHighlightStyle s
10171016deprecatedOption :: String -> String -> IO ()
10181017deprecatedOption o msg =
10191018 runIO (report $ Deprecated (T.pack o) (T.pack msg)) >>=
1020− \r -> case r of
1019+ \case
10211020 Right () -> return ()
10221021 Left e -> E.throwIO e
10231022
src/Text/Pandoc/Class/PandocMonad.hs+5−5
@@ -433,7 +433,7 @@ getDefaultReferenceDocx = do
433433 "word/theme/theme1.xml"]
434434 let toLazy = BL.fromChunks . (:[])
435435 let pathToEntry path = do
436− epochtime <- (floor . utcTimeToPOSIXSeconds) <$> getCurrentTime
436+ epochtime <- floor . utcTimeToPOSIXSeconds <$> getCurrentTime
437437 contents <- toLazy <$> readDataFile ("docx/" ++ path)
438438 return $ toEntry path epochtime contents
439439 datadir <- getUserDataDir
@@ -536,7 +536,7 @@ getDefaultReferencePptx = do
536536 ]
537537 let toLazy = BL.fromChunks . (:[])
538538 let pathToEntry path = do
539− epochtime <- (floor . utcTimeToPOSIXSeconds) <$> getCurrentTime
539+ epochtime <- floor . utcTimeToPOSIXSeconds <$> getCurrentTime
540540 contents <- toLazy <$> readDataFile ("pptx/" ++ path)
541541 return $ toEntry path epochtime contents
542542 datadir <- getUserDataDir
@@ -568,11 +568,11 @@ readDataFile fname = do
568568-- | Read file from from Cabal data directory.
569569readDefaultDataFile :: PandocMonad m => FilePath -> m B.ByteString
570570readDefaultDataFile "reference.docx" =
571− (B.concat . BL.toChunks . fromArchive) <$> getDefaultReferenceDocx
571+ B.concat . BL.toChunks . fromArchive <$> getDefaultReferenceDocx
572572readDefaultDataFile "reference.pptx" =
573− (B.concat . BL.toChunks . fromArchive) <$> getDefaultReferencePptx
573+ B.concat . BL.toChunks . fromArchive <$> getDefaultReferencePptx
574574readDefaultDataFile "reference.odt" =
575− (B.concat . BL.toChunks . fromArchive) <$> getDefaultReferenceODT
575+ B.concat . BL.toChunks . fromArchive <$> getDefaultReferenceODT
576576readDefaultDataFile fname =
577577#ifdef EMBED_DATA_FILES
578578 case lookup (makeCanonical fname) dataFiles of
src/Text/Pandoc/Image.hs−1
@@ -1,5 +1,4 @@
11{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, CPP #-}
2−{-# LANGUAGE ViewPatterns #-}
32{- |
43Module : Text.Pandoc.Image
54Copyright : Copyright (C) 2020 John MacFarlane
src/Text/Pandoc/Logging.hs+2−2
@@ -1,5 +1,6 @@
11{-# LANGUAGE DeriveDataTypeable #-}
22{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE LambdaCase #-}
34{-# LANGUAGE OverloadedStrings #-}
45{- |
56 Module : Text.Pandoc.Logging
@@ -51,8 +52,7 @@ instance FromJSON Verbosity where
5152 parseJSON _ = mzero
5253
5354instance FromYAML Verbosity where
54− parseYAML = withStr "Verbosity" $ \t ->
55− case t of
55+ parseYAML = withStr "Verbosity" $ \case
5656 "ERROR" -> return ERROR
5757 "WARNING" -> return WARNING
5858 "INFO" -> return INFO
src/Text/Pandoc/Lua/Marshaling/AST.hs+1−3
@@ -230,9 +230,7 @@ peekCaption idx = do
230230instance Peekable ColWidth where
231231 peek idx = do
232232 width <- Lua.fromOptional <$> Lua.peek idx
233− return $ case width of
234− Nothing -> ColWidthDefault
235− Just w -> ColWidth w
233+ return $ maybe ColWidthDefault ColWidth width
236234
237235instance Pushable ColWidth where
238236 push = \case
src/Text/Pandoc/Lua/Module/Utils.hs+2−3
@@ -50,9 +50,8 @@ pushModule = do
5050-- | Squashes a list of blocks into inlines.
5151blocksToInlines :: [Block] -> Lua.Optional [Inline] -> PandocLua [Inline]
5252blocksToInlines blks optSep = liftPandocLua $ do
53− let sep = case Lua.fromOptional optSep of
54− Just x -> B.fromList x
55− Nothing -> Shared.defaultBlocksSeparator
53+ let sep = maybe Shared.defaultBlocksSeparator B.fromList
54+ $ Lua.fromOptional optSep
5655 return $ B.toList (Shared.blocksToInlinesWithSep sep blks)
5756
5857-- | Convert list of Pandoc blocks into sections using Divs.
src/Text/Pandoc/Options.hs+3−2
@@ -1,8 +1,9 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE DeriveDataTypeable #-}
33{-# LANGUAGE DeriveGeneric #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE LambdaCase #-}
55{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE TemplateHaskell #-}
67{- |
78 Module : Text.Pandoc.Options
89 Copyright : Copyright (C) 2012-2020 John MacFarlane
@@ -327,7 +328,7 @@ $(deriveJSON defaultOptions{ constructorTagModifier =
327328 } ''CiteMethod)
328329
329330$(deriveJSON defaultOptions{ constructorTagModifier =
330− \t -> case t of
331+ \case
331332 "NoObfuscation" -> "none"
332333 "ReferenceObfuscation" -> "references"
333334 "JavascriptObfuscation" -> "javascript"
src/Text/Pandoc/PDF.hs+2−2
@@ -1,4 +1,5 @@
11{-# LANGUAGE CPP #-}
2+{-# LANGUAGE LambdaCase #-}
23{-# LANGUAGE OverloadedStrings #-}
34{-# LANGUAGE ScopedTypeVariables #-}
45{- |
@@ -201,8 +202,7 @@ convertImage opts tmpdir fname = do
201202 (\(e :: E.SomeException) -> return $ Left $
202203 "check that rsvg-convert is in path.\n" <>
203204 tshow e)
204− _ -> JP.readImage fname >>= \res ->
205− case res of
205+ _ -> JP.readImage fname >>= \case
206206 Left e -> return $ Left $ T.pack e
207207 Right img ->
208208 E.catch (Right pngOut <$ JP.savePngImage pngOut img) $
src/Text/Pandoc/Parsing.hs+7−9
@@ -574,15 +574,15 @@ romanNumeral upperCase = do
574574 let fivehundred = rchar 'D'
575575 let thousand = rchar 'M'
576576 lookAhead $ choice [one, five, ten, fifty, hundred, fivehundred, thousand]
577− thousands <- ((1000 *) . length) <$> many thousand
577+ thousands <- (1000 *) . length <$> many thousand
578578 ninehundreds <- option 0 $ try $ hundred >> thousand >> return 900
579579 fivehundreds <- option 0 $ 500 <$ fivehundred
580580 fourhundreds <- option 0 $ try $ hundred >> fivehundred >> return 400
581− hundreds <- ((100 *) . length) <$> many hundred
581+ hundreds <- (100 *) . length <$> many hundred
582582 nineties <- option 0 $ try $ ten >> hundred >> return 90
583583 fifties <- option 0 (50 <$ fifty)
584584 forties <- option 0 $ try $ ten >> fifty >> return 40
585− tens <- ((10 *) . length) <$> many ten
585+ tens <- (10 *) . length <$> many ten
586586 nines <- option 0 $ try $ one >> ten >> return 9
587587 fives <- option 0 (5 <$ five)
588588 fours <- option 0 $ try $ one >> five >> return 4
@@ -951,7 +951,7 @@ tableWith' headerParser rowParser lineParser footerParser = try $ do
951951 then replicate (length aligns) 0.0
952952 else widthsFromIndices numColumns indices
953953 let toRow = Row nullAttr . map B.simpleCell
954− toHeaderRow l = if null l then [] else [toRow l]
954+ toHeaderRow l = [toRow l | not (null l)]
955955 return (aligns, widths, toHeaderRow <$> heads, map toRow <$> lines')
956956
957957-- Calculate relative widths of table columns, based on indices
@@ -1170,7 +1170,7 @@ class HasReaderOptions st where
11701170 extractReaderOptions :: st -> ReaderOptions
11711171 getOption :: (Stream s m t) => (ReaderOptions -> b) -> ParserT s st m b
11721172 -- default
1173− getOption f = (f . extractReaderOptions) <$> getState
1173+ getOption f = f . extractReaderOptions <$> getState
11741174
11751175instance HasReaderOptions ParserState where
11761176 extractReaderOptions = stateOptions
@@ -1492,10 +1492,8 @@ extractIdClass :: Attr -> Attr
14921492extractIdClass (ident, cls, kvs) = (ident', cls', kvs')
14931493 where
14941494 ident' = fromMaybe ident (lookup "id" kvs)
1495− cls' = case lookup "class" kvs of
1496− Just cl -> T.words cl
1497− Nothing -> cls
1498− kvs' = filter (\(k,_) -> k /= "id" || k /= "class") kvs
1495+ cls' = maybe cls T.words $ lookup "class" kvs
1496+ kvs' = filter (\(k,_) -> k /= "id" || k /= "class") kvs
14991497
15001498insertIncludedFile' :: (PandocMonad m, HasIncludeFiles st)
15011499 => ParserT a st m (mf Blocks)
src/Text/Pandoc/Readers/CSV.hs+1−1
@@ -39,7 +39,7 @@ readCSV _opts s =
3939 numcols = length r
4040 toplain = B.simpleCell . B.plain . B.text . T.strip
4141 toRow = Row nullAttr . map toplain
42− toHeaderRow l = if null l then [] else [toRow l]
42+ toHeaderRow l = [toRow l | not (null l)]
4343 hdrs = toHeaderRow r
4444 rows = map toRow rs
4545 aligns = replicate numcols AlignDefault
src/Text/Pandoc/Readers/CommonMark.hs−1
@@ -1,6 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
22{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE ViewPatterns #-}
43{- |
54 Module : Text.Pandoc.Readers.CommonMark
65 Copyright : Copyright (C) 2015-2020 John MacFarlane
src/Text/Pandoc/Readers/DocBook.hs+11−11
@@ -18,7 +18,7 @@ import Data.Either (rights)
1818import Data.Foldable (asum)
1919import Data.Generics
2020import Data.List (intersperse,elemIndex)
21−import Data.Maybe (fromMaybe,catMaybes)
21+import Data.Maybe (fromMaybe,mapMaybe)
2222import Data.Text (Text)
2323import qualified Data.Text as T
2424import Text.HTML.TagSoup.Entity (lookupEntity)
@@ -781,7 +781,7 @@ parseBlock (Elem e) =
781781 "para" -> parseMixed para (elContent e)
782782 "formalpara" -> do
783783 tit <- case filterChild (named "title") e of
784− Just t -> (para . strong . (<> str ".")) <$>
784+ Just t -> para . strong . (<> str ".") <$>
785785 getInlines t
786786 Nothing -> return mempty
787787 (tit <>) <$> parseMixed para (elContent e)
@@ -897,7 +897,7 @@ parseBlock (Elem e) =
897897 parseBlockquote = do
898898 attrib <- case filterChild (named "attribution") e of
899899 Nothing -> return mempty
900− Just z -> (para . (str "— " <>) . mconcat)
900+ Just z -> para . (str "— " <>) . mconcat
901901 <$>
902902 mapM parseInline (elContent z)
903903 contents <- getBlocks e
@@ -931,7 +931,7 @@ parseBlock (Elem e) =
931931 _ -> filterChildren isColspec e'
932932 let colnames = case colspecs of
933933 [] -> []
934− cs -> catMaybes $ map (findAttr (unqual "colname" )) cs
934+ cs -> mapMaybe (findAttr (unqual "colname" )) cs
935935 let isRow x = named "row" x || named "tr" x
936936 headrows <- case filterChild (named "thead") e' of
937937 Just h -> case filterChild isRow h of
@@ -968,7 +968,7 @@ parseBlock (Elem e) =
968968 in ColWidth . (/ tot) <$> ws'
969969 Nothing -> replicate numrows ColWidthDefault
970970 let toRow = Row nullAttr
971− toHeaderRow l = if null l then [] else [toRow l]
971+ toHeaderRow l = [toRow l | not (null l)]
972972 return $ table (simpleCaption $ plain capt)
973973 (zip aligns widths)
974974 (TableHead nullAttr $ toHeaderRow headrows)
@@ -1008,7 +1008,7 @@ parseBlock (Elem e) =
10081008parseMixed :: PandocMonad m => (Inlines -> Blocks) -> [Content] -> DB m Blocks
10091009parseMixed container conts = do
10101010 let (ils,rest) = break isBlockElement conts
1011− ils' <- (trimInlines . mconcat) <$> mapM parseInline ils
1011+ ils' <- trimInlines . mconcat <$> mapM parseInline ils
10121012 let p = if ils' == mempty then mempty else container ils'
10131013 case rest of
10141014 [] -> return p
@@ -1036,10 +1036,10 @@ parseEntry cn el = do
10361036 case (mStrt, mEnd) of
10371037 (Just start, Just end) -> colDistance start end
10381038 _ -> 1
1039− (fmap (cell AlignDefault 1 (toColSpan el)) . (parseMixed plain) . elContent) el
1039+ (fmap (cell AlignDefault 1 (toColSpan el)) . parseMixed plain . elContent) el
10401040
10411041getInlines :: PandocMonad m => Element -> DB m Inlines
1042−getInlines e' = (trimInlines . mconcat) <$>
1042+getInlines e' = trimInlines . mconcat <$>
10431043 mapM parseInline (elContent e')
10441044
10451045strContentRecursive :: Element -> String
@@ -1136,7 +1136,7 @@ parseInline (Elem e) =
11361136 "strong" -> strong <$> innerInlines
11371137 "strikethrough" -> strikeout <$> innerInlines
11381138 _ -> emph <$> innerInlines
1139− "footnote" -> (note . mconcat) <$>
1139+ "footnote" -> note . mconcat <$>
11401140 mapM parseBlock (elContent e)
11411141 "title" -> return mempty
11421142 "affiliation" -> skip
@@ -1149,14 +1149,14 @@ parseInline (Elem e) =
11491149 lift $ report $ IgnoredElement $ T.pack $ qName (elName e)
11501150 return mempty
11511151
1152− innerInlines = (trimInlines . mconcat) <$>
1152+ innerInlines = trimInlines . mconcat <$>
11531153 mapM parseInline (elContent e)
11541154 codeWithLang = do
11551155 let classes' = case attrValue "language" e of
11561156 "" -> []
11571157 l -> [l]
11581158 return $ codeWith (attrValue "id" e,classes',[]) $ T.pack $ strContentRecursive e
1159− simpleList = (mconcat . intersperse (str "," <> space)) <$> mapM getInlines
1159+ simpleList = mconcat . intersperse (str "," <> space) <$> mapM getInlines
11601160 (filterChildren (named "member") e)
11611161 segmentedList = do
11621162 tit <- maybe (return mempty) getInlines $ filterChild (named "title") e
src/Text/Pandoc/Readers/Docx.hs+5−5
@@ -91,9 +91,9 @@ readDocx :: PandocMonad m
9191 => ReaderOptions
9292 -> B.ByteString
9393 -> m Pandoc
94−readDocx opts bytes = do
94+readDocx opts bytes =
9595 case toArchiveOrFail bytes of
96− Right archive -> do
96+ Right archive ->
9797 case archiveToDocxWithWarnings archive of
9898 Right (docx, parserWarnings) -> do
9999 mapM_ (P.report . DocxParserWarning) parserWarnings
@@ -291,9 +291,9 @@ runStyleToTransform rPr' = do
291291 spanWith ("",[],[("dir","ltr")]) . go rPr{isRTL = Nothing}
292292 | Just SupScrpt <- rVertAlign rPr =
293293 superscript . go rPr{rVertAlign = Nothing}
294− | Just SubScrpt <- rVertAlign rPr = do
294+ | Just SubScrpt <- rVertAlign rPr =
295295 subscript . go rPr{rVertAlign = Nothing}
296− | Just "single" <- rUnderline rPr = do
296+ | Just "single" <- rUnderline rPr =
297297 Pandoc.underline . go rPr{rUnderline = Nothing}
298298 | otherwise = id
299299 return $ go rPr'
@@ -658,7 +658,7 @@ bodyPartToBlocks (Tbl cap _ look parts@(r:rs)) = do
658658 rowLength (Docx.Row c) = length c
659659
660660 let toRow = Pandoc.Row nullAttr . map simpleCell
661− toHeaderRow l = if null l then [] else [toRow l]
661+ toHeaderRow l = [toRow l | not (null l)]
662662
663663 -- pad cells. New Text.Pandoc.Builder will do that for us,
664664 -- so this is for compatibility while we switch over.
src/Text/Pandoc/Readers/Docx/Parse.hs+3−9
@@ -404,12 +404,8 @@ archiveToNotes zf =
404404 >>= (parseXMLDoc . UTF8.toStringLazy . fromEntry)
405405 enElem = findEntryByPath "word/endnotes.xml" zf
406406 >>= (parseXMLDoc . UTF8.toStringLazy . fromEntry)
407− fn_namespaces = case fnElem of
408− Just e -> elemToNameSpaces e
409− Nothing -> []
410− en_namespaces = case enElem of
411− Just e -> elemToNameSpaces e
412− Nothing -> []
407+ fn_namespaces = maybe [] elemToNameSpaces fnElem
408+ en_namespaces = maybe [] elemToNameSpaces enElem
413409 ns = unionBy (\x y -> fst x == fst y) fn_namespaces en_namespaces
414410 fn = fnElem >>= walkDocument ns >>= elemToNotes ns "footnote"
415411 en = enElem >>= walkDocument ns >>= elemToNotes ns "endnote"
@@ -420,9 +416,7 @@ archiveToComments :: Archive -> Comments
420416archiveToComments zf =
421417 let cmtsElem = findEntryByPath "word/comments.xml" zf
422418 >>= (parseXMLDoc . UTF8.toStringLazy . fromEntry)
423− cmts_namespaces = case cmtsElem of
424− Just e -> elemToNameSpaces e
425− Nothing -> []
419+ cmts_namespaces = maybe [] elemToNameSpaces cmtsElem
426420 cmts = elemToComments cmts_namespaces <$> (cmtsElem >>= walkDocument cmts_namespaces)
427421 in
428422 case cmts of
src/Text/Pandoc/Readers/DokuWiki.hs+1−1
@@ -472,7 +472,7 @@ table = do
472472 else ([], rows)
473473 let attrs = (AlignDefault, ColWidthDefault) <$ transpose rows
474474 let toRow = Row nullAttr . map B.simpleCell
475− toHeaderRow l = if null l then [] else [toRow l]
475+ toHeaderRow l = [toRow l | not (null l)]
476476 pure $ B.table B.emptyCaption
477477 attrs
478478 (TableHead nullAttr $ toHeaderRow headerRow)
src/Text/Pandoc/Readers/HTML.hs+1−1
@@ -517,7 +517,7 @@ pTable = try $ do
517517 else replicate cols (ColWidth (1.0 / fromIntegral cols))
518518 else widths'
519519 let toRow = Row nullAttr . map B.simpleCell
520− toHeaderRow l = if null l then [] else [toRow l]
520+ toHeaderRow l = [toRow l | not (null l)]
521521 return $ B.tableWith attribs
522522 (B.simpleCaption $ B.plain caption)
523523 (zip aligns widths)
src/Text/Pandoc/Readers/Haddock.hs+1−1
@@ -86,7 +86,7 @@ docHToBlocks d' =
8686 }
8787 -> let toCells = map (docHToBlocks . tableCellContents) . tableRowCells
8888 toRow = Row nullAttr . map B.simpleCell
89− toHeaderRow l = if null l then [] else [toRow l]
89+ toHeaderRow l = [toRow l | not (null l)]
9090 (header, body) =
9191 if null headerRows
9292 then ([], map toCells bodyRows)
src/Text/Pandoc/Readers/JATS.hs+6−6
@@ -189,7 +189,7 @@ parseBlock (Elem e) =
189189 _ -> getBlocks e
190190 where parseMixed container conts = do
191191 let (ils,rest) = break isBlockElement conts
192− ils' <- (trimInlines . mconcat) <$> mapM parseInline ils
192+ ils' <- trimInlines . mconcat <$> mapM parseInline ils
193193 let p = if ils' == mempty then mempty else container ils'
194194 case rest of
195195 [] -> return p
@@ -206,7 +206,7 @@ parseBlock (Elem e) =
206206 parseBlockquote = do
207207 attrib <- case filterChild (named "attribution") e of
208208 Nothing -> return mempty
209− Just z -> (para . (str "— " <>) . mconcat)
209+ Just z -> para . (str "— " <>) . mconcat
210210 <$>
211211 mapM parseInline (elContent z)
212212 contents <- getBlocks e
@@ -281,7 +281,7 @@ parseBlock (Elem e) =
281281 in ColWidth . (/ tot) <$> ws'
282282 Nothing -> replicate numrows ColWidthDefault
283283 let toRow = Row nullAttr . map simpleCell
284− toHeaderRow l = if null l then [] else [toRow l]
284+ toHeaderRow l = [toRow l | not (null l)]
285285 return $ table (simpleCaption $ plain capt)
286286 (zip aligns widths)
287287 (TableHead nullAttr $ toHeaderRow headrows)
@@ -309,7 +309,7 @@ parseBlock (Elem e) =
309309 return $ headerWith (ident,[],[]) n' headerText <> b
310310
311311getInlines :: PandocMonad m => Element -> JATS m Inlines
312−getInlines e' = (trimInlines . mconcat) <$>
312+getInlines e' = trimInlines . mconcat <$>
313313 mapM parseInline (elContent e')
314314
315315parseMetadata :: PandocMonad m => Element -> JATS m Blocks
@@ -518,10 +518,10 @@ parseInline (Elem e) =
518518 "email" -> return $ link ("mailto:" <> textContent e) ""
519519 $ str $ textContent e
520520 "uri" -> return $ link (textContent e) "" $ str $ textContent e
521− "fn" -> (note . mconcat) <$>
521+ "fn" -> note . mconcat <$>
522522 mapM parseBlock (elContent e)
523523 _ -> innerInlines
524− where innerInlines = (trimInlines . mconcat) <$>
524+ where innerInlines = trimInlines . mconcat <$>
525525 mapM parseInline (elContent e)
526526 mathML x =
527527 case readMathML . T.pack . showElement $ everywhere (mkT removePrefix) x of
src/Text/Pandoc/Readers/LaTeX.hs+31−32
@@ -31,6 +31,7 @@ import Control.Monad
3131import Control.Monad.Except (throwError)
3232import Data.Char (isDigit, isLetter, toUpper, chr)
3333import Data.Default
34+import Data.Functor (($>))
3435import Data.List (intercalate)
3536import qualified Data.Map as M
3637import Data.Maybe (fromMaybe, maybeToList)
@@ -136,15 +137,15 @@ rawLaTeXBlock = do
136137 inp <- getInput
137138 let toks = tokenize "source" inp
138139 snd <$> (rawLaTeXParser toks False (macroDef (const mempty)) blocks
139− <|> (rawLaTeXParser toks True
140+ <|> rawLaTeXParser toks True
140141 (do choice (map controlSeq
141142 ["include", "input", "subfile", "usepackage"])
142143 skipMany opt
143144 braced
144− return mempty) blocks)
145+ return mempty) blocks
145146 <|> rawLaTeXParser toks True
146147 (environment <|> blockCommand)
147− (mconcat <$> (many (block <|> beginOrEndCommand))))
148+ (mconcat <$> many (block <|> beginOrEndCommand)))
148149
149150-- See #4667 for motivation; sometimes people write macros
150151-- that just evaluate to a begin or end command, which blockCommand
@@ -187,10 +188,10 @@ inlineCommand = do
187188-- inline elements:
188189
189190word :: PandocMonad m => LP m Inlines
190−word = (str . untoken) <$> satisfyTok isWordTok
191+word = str . untoken <$> satisfyTok isWordTok
191192
192193regularSymbol :: PandocMonad m => LP m Inlines
193−regularSymbol = (str . untoken) <$> satisfyTok isRegularSymbol
194+regularSymbol = str . untoken <$> satisfyTok isRegularSymbol
194195 where isRegularSymbol (Tok _ Symbol t) = not $ T.any isSpecial t
195196 isRegularSymbol _ = False
196197 isSpecial c = c `Set.member` specialChars
@@ -206,7 +207,7 @@ inlineGroup = do
206207
207208doLHSverb :: PandocMonad m => LP m Inlines
208209doLHSverb =
209− (codeWith ("",["haskell"],[]) . untokenize)
210+ codeWith ("",["haskell"],[]) . untokenize
210211 <$> manyTill (satisfyTok (not . isNewlineTok)) (symbol '|')
211212
212213mkImage :: PandocMonad m => [(Text, Text)] -> Text -> LP m Inlines
@@ -342,7 +343,7 @@ doverb = do
342343 Just (c, ts) | T.null ts -> return c
343344 _ -> mzero
344345 withVerbatimMode $
345− (code . untokenize) <$>
346+ code . untokenize <$>
346347 manyTill (notFollowedBy newlineTok >> verbTok marker) (symbol marker)
347348
348349verbTok :: PandocMonad m => Char -> LP m Tok
@@ -383,7 +384,7 @@ doinlinecode classes = do
383384 _ -> mzero
384385 let stopchar = if marker == '{' then '}' else marker
385386 withVerbatimMode $
386− (codeWith ("",classes,[]) . T.map nlToSpace . untokenize) <$>
387+ codeWith ("",classes,[]) . T.map nlToSpace . untokenize <$>
387388 manyTill (verbTok stopchar) (symbol stopchar)
388389
389390nlToSpace :: Char -> Char
@@ -402,7 +403,7 @@ dollarsMath = do
402403 display <- option False (True <$ symbol '$')
403404 (do contents <- try $ untokenize <$> pDollarsMath 0
404405 if display
405− then (mathDisplay contents <$ symbol '$')
406+ then mathDisplay contents <$ symbol '$'
406407 else return $ mathInline contents)
407408 <|> (guard display >> return (mathInline ""))
408409
@@ -415,7 +416,7 @@ pDollarsMath n = do
415416 , n == 0 -> return []
416417 | t == "\\" -> do
417418 tk' <- anyTok
418− ((tk :) . (tk' :)) <$> pDollarsMath n
419+ (tk :) . (tk' :) <$> pDollarsMath n
419420 | t == "{" -> (tk :) <$> pDollarsMath (n+1)
420421 | t == "}" ->
421422 if n > 0
@@ -477,7 +478,7 @@ cites mode multi = try $ do
477478 tempCits <- many1 simpleCiteArgs
478479 case tempCits of
479480 (k:ks) -> case ks of
480− (_:_) -> return $ ((addMprenote pre k):init ks) ++
481+ (_:_) -> return $ (addMprenote pre k : init ks) ++
481482 [addMpostnote suf (last ks)]
482483 _ -> return [addMprenote pre (addMpostnote suf k)]
483484 _ -> return [[]]
@@ -521,7 +522,7 @@ complexNatbibCitation mode = try $ do
521522 bgroup
522523 items <- mconcat <$>
523524 many1 (notFollowedBy (symbol ';') >> inline)
524− `sepBy1` (symbol ';')
525+ `sepBy1` symbol ';'
525526 egroup
526527 return $ map handleCitationPart items
527528 case cs of
@@ -660,7 +661,7 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
660661 , ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty
661662 , ("mbox", rawInlineOr "mbox" $ processHBox <$> tok)
662663 , ("hbox", rawInlineOr "hbox" $ processHBox <$> tok)
663− , ("lettrine", rawInlineOr "lettrine" $ lettrine)
664+ , ("lettrine", rawInlineOr "lettrine" lettrine)
664665 , ("(", mathInline . untokenize <$> manyTill anyTok (controlSeq ")"))
665666 , ("[", mathDisplay . untokenize <$> manyTill anyTok (controlSeq "]"))
666667 , ("ensuremath", mathInline . untokenize <$> braced)
@@ -1073,7 +1074,7 @@ coloredInline stylename = do
10731074 spanWith ("",[],[("style",stylename <> ": " <> untokenize color)]) <$> tok
10741075
10751076ttfamily :: PandocMonad m => LP m Inlines
1076−ttfamily = (code . stringify . toList) <$> tok
1077+ttfamily = code . stringify . toList <$> tok
10771078
10781079rawInlineOr :: PandocMonad m => Text -> LP m Inlines -> LP m Inlines
10791080rawInlineOr name' fallback = do
@@ -1235,8 +1236,8 @@ doSubfile = do
12351236include :: (PandocMonad m, Monoid a) => Text -> LP m a
12361237include name = do
12371238 skipMany opt
1238− fs <- (map (T.unpack . removeDoubleQuotes . T.strip) . T.splitOn "," .
1239− untokenize) <$> braced
1239+ fs <- map (T.unpack . removeDoubleQuotes . T.strip) . T.splitOn "," .
1240+ untokenize <$> braced
12401241 let defaultExt | name == "usepackage" = ".sty"
12411242 | otherwise = ".tex"
12421243 mapM_ (insertIncluded defaultExt) fs
@@ -1251,7 +1252,7 @@ insertIncluded defaultExtension f' = do
12511252 ".tex" -> f'
12521253 ".sty" -> f'
12531254 _ -> addExtension f' defaultExtension
1254− dirs <- (map T.unpack . splitTextBy (==':') . fromMaybe ".") <$> lookupEnv "TEXINPUTS"
1255+ dirs <- map T.unpack . splitTextBy (==':') . fromMaybe "." <$> lookupEnv "TEXINPUTS"
12551256 pos <- getPosition
12561257 containers <- getIncludeFiles <$> getState
12571258 when (T.pack f `elem` containers) $
@@ -1564,7 +1565,7 @@ blockCommands = M.fromList
15641565 , ("frametitle", section nullAttr 3)
15651566 , ("framesubtitle", section nullAttr 4)
15661567 -- letters
1567− , ("opening", (para . trimInlines) <$> (skipopts *> tok))
1568+ , ("opening", para . trimInlines <$> (skipopts *> tok))
15681569 , ("closing", skipopts *> closing)
15691570 -- memoir
15701571 , ("plainbreak", braced >> pure horizontalRule)
@@ -1578,10 +1579,10 @@ blockCommands = M.fromList
15781579 --
15791580 , ("hrule", pure horizontalRule)
15801581 , ("strut", pure mempty)
1581− , ("rule", skipopts *> tok *> tok *> pure horizontalRule)
1582+ , ("rule", skipopts *> tok *> tok $> horizontalRule)
15821583 , ("item", looseItem)
15831584 , ("documentclass", skipopts *> braced *> preamble)
1584− , ("centerline", (para . trimInlines) <$> (skipopts *> tok))
1585+ , ("centerline", para . trimInlines <$> (skipopts *> tok))
15851586 , ("caption", mempty <$ setCaption)
15861587 , ("bibliography", mempty <$ (skipopts *> braced >>=
15871588 addMeta "bibliography" . splitBibs . untokenize))
@@ -1623,7 +1624,7 @@ environments :: PandocMonad m => M.Map Text (LP m Blocks)
16231624environments = M.fromList
16241625 [ ("document", env "document" blocks <* skipMany anyTok)
16251626 , ("abstract", mempty <$ (env "abstract" blocks >>= addMeta "abstract"))
1626− , ("sloppypar", env "sloppypar" $ blocks)
1627+ , ("sloppypar", env "sloppypar" blocks)
16271628 , ("letter", env "letter" letterContents)
16281629 , ("minipage", env "minipage" $
16291630 skipopts *> spaces *> optional braced *> spaces *> blocks)
@@ -1709,7 +1710,7 @@ proof = do
17091710 bs <- env "proof" blocks
17101711 return $
17111712 B.divWith ("", ["proof"], []) $
1712− addQed $ addTitle (B.emph (title <> ".")) $ bs
1713+ addQed $ addTitle (B.emph (title <> ".")) bs
17131714
17141715addTitle :: Inlines -> Blocks -> Blocks
17151716addTitle ils bs =
@@ -1753,8 +1754,7 @@ theoremEnvironment name = do
17531754 then do
17541755 let name' = fromMaybe name $ theoremSeries tspec
17551756 num <- getNextNumber
1756− (fromMaybe (DottedNum [0]) .
1757− fmap theoremLastNum .
1757+ (maybe (DottedNum [0]) theoremLastNum .
17581758 M.lookup name' . sTheoremMap)
17591759 updateState $ \s ->
17601760 s{ sTheoremMap =
@@ -1866,7 +1866,7 @@ inputMinted = do
18661866 pos <- getPosition
18671867 attr <- mintedAttr
18681868 f <- T.filter (/='"') . untokenize <$> braced
1869− dirs <- (map T.unpack . splitTextBy (==':') . fromMaybe ".") <$> lookupEnv "TEXINPUTS"
1869+ dirs <- map T.unpack . splitTextBy (==':') . fromMaybe "." <$> lookupEnv "TEXINPUTS"
18701870 mbCode <- readFileFromDirs dirs (T.unpack f)
18711871 rawcode <- case mbCode of
18721872 Just s -> return s
@@ -1979,7 +1979,7 @@ inputListing = do
19791979 pos <- getPosition
19801980 options <- option [] keyvals
19811981 f <- T.filter (/='"') . untokenize <$> braced
1982− dirs <- (map T.unpack . splitTextBy (==':') . fromMaybe ".") <$> lookupEnv "TEXINPUTS"
1982+ dirs <- map T.unpack . splitTextBy (==':') . fromMaybe "." <$> lookupEnv "TEXINPUTS"
19831983 mbCode <- readFileFromDirs dirs (T.unpack f)
19841984 codeLines <- case mbCode of
19851985 Just s -> return $ T.lines s
@@ -2176,18 +2176,17 @@ parseTableCell :: PandocMonad m => LP m Cell
21762176parseTableCell = do
21772177 spaces
21782178 updateState $ \st -> st{ sInTableCell = True }
2179− cell' <- ( multicolumnCell
2179+ cell' <- multicolumnCell
21802180 <|> multirowCell
21812181 <|> parseSimpleCell
21822182 <|> parseEmptyCell
2183− )
21842183 updateState $ \st -> st{ sInTableCell = False }
21852184 spaces
21862185 return cell'
21872186 where
21882187 -- The parsing of empty cells is important in LaTeX, especially when dealing
21892188 -- with multirow/multicolumn. See #6603.
2190− parseEmptyCell = optional spaces >> return emptyCell <* optional spaces
2189+ parseEmptyCell = spaces $> emptyCell
21912190
21922191cellAlignment :: PandocMonad m => LP m Alignment
21932192cellAlignment = skipMany (symbol '|') *> alignment <* skipMany (symbol '|')
@@ -2237,8 +2236,8 @@ multicolumnCell = controlSeq "multicolumn" >> do
22372236 (Cell _ _ (RowSpan rs) _ bs) <- multirowCell
22382237 return $ cell
22392238 alignment
2240− (RowSpan $ rs)
2241− (ColSpan $ span')
2239+ (RowSpan rs)
2240+ (ColSpan span')
22422241 (fromList bs)
22432242
22442243 symbol '{' *> (nestedCell <|> singleCell) <* symbol '}'
@@ -2276,7 +2275,7 @@ simpTable envname hasWidthParameter = try $ do
22762275 lookAhead $ controlSeq "end" -- make sure we're at end
22772276 return $ table emptyCaption
22782277 (zip aligns widths)
2279− (TableHead nullAttr $ header')
2278+ (TableHead nullAttr header')
22802279 [TableBody nullAttr 0 [] rows]
22812280 (TableFoot nullAttr [])
22822281
src/Text/Pandoc/Readers/LaTeX/Lang.hs+1−1
@@ -152,4 +152,4 @@ babelLangToBCP47 s =
152152 "newzealand" -> Just $ Lang "en" "" "NZ" []
153153 "american" -> Just $ Lang "en" "" "US" []
154154 "classiclatin" -> Just $ Lang "la" "" "" ["x-classic"]
155− _ -> fmap ($ "") $ M.lookup s polyglossiaLangToBCP47
155+ _ -> ($ "") <$> M.lookup s polyglossiaLangToBCP47
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+6−8
@@ -1,8 +1,8 @@
11{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE LambdaCase #-}
23{-# LANGUAGE MultiParamTypeClasses #-}
34{-# LANGUAGE OverloadedStrings #-}
45{-# LANGUAGE ScopedTypeVariables #-}
5−{-# LANGUAGE ViewPatterns #-}
66{- |
77 Module : Text.Pandoc.Readers.LaTeX.Parsing
88 Copyright : Copyright (C) 2006-2020 John MacFarlane
@@ -736,14 +736,14 @@ keyval = try $ do
736736 (mconcat <$> many1 (
737737 (untokenize . snd <$> withRaw braced)
738738 <|>
739− (untokenize <$> (many1
739+ (untokenize <$> many1
740740 (satisfyTok
741− (\t -> case t of
741+ (\case
742742 Tok _ Symbol "]" -> False
743743 Tok _ Symbol "," -> False
744744 Tok _ Symbol "{" -> False
745745 Tok _ Symbol "}" -> False
746− _ -> True))))))
746+ _ -> True)))))
747747 optional (symbol ',')
748748 sp
749749 return (key, T.strip val)
@@ -756,8 +756,7 @@ verbEnv name = withVerbatimMode $ do
756756 optional blankline
757757 res <- manyTill anyTok (end_ name)
758758 return $ stripTrailingNewline
759− $ untokenize
760− $ res
759+ $ untokenize res
761760
762761-- Strip single final newline and any spaces following it.
763762-- Input is unchanged if it doesn't end with newline +
@@ -819,8 +818,7 @@ overlaySpecification = try $ do
819818
820819overlayTok :: PandocMonad m => LP m Tok
821820overlayTok =
822− satisfyTok (\t ->
823− case t of
821+ satisfyTok (\case
824822 Tok _ Word _ -> True
825823 Tok _ Spaces _ -> True
826824 Tok _ Symbol c -> c `elem` ["-","+","@","|",":",","]
src/Text/Pandoc/Readers/LaTeX/SIunitx.hs+3−3
@@ -103,9 +103,9 @@ doSIang = do
103103 ps <- T.splitOn ";" . untokenize <$> braced
104104 case ps ++ repeat "" of
105105 (d:m:s:_) -> return $
106− (if T.null d then mempty else (str d <> str "\xb0")) <>
107− (if T.null m then mempty else (str m <> str "\x2032")) <>
108− (if T.null s then mempty else (str s <> str "\x2033"))
106+ (if T.null d then mempty else str d <> str "\xb0") <>
107+ (if T.null m then mempty else str m <> str "\x2032") <>
108+ (if T.null s then mempty else str s <> str "\x2033")
109109 _ -> return mempty
110110
111111-- converts e.g. \SIrange{100}{200}{\ms} to "100 ms--200 ms"
src/Text/Pandoc/Readers/Man.hs+1−1
@@ -162,7 +162,7 @@ parseTable = do
162162 _ -> Nothing
163163
164164 toRow = Row nullAttr . map simpleCell
165− toHeaderRow l = if null l then [] else [toRow l]
165+ toHeaderRow l = [toRow l | not (null l)]
166166
167167parseNewParagraph :: PandocMonad m => ManParser m Blocks
168168parseNewParagraph = do
src/Text/Pandoc/Readers/Markdown.hs+6−6
@@ -1025,7 +1025,7 @@ htmlBlock = do
10251025 guardEnabled Ext_raw_html
10261026 try (do
10271027 (TagOpen _ attrs) <- lookAhead $ fst <$> htmlTag isBlockTag
1028− (return . B.rawBlock "html") <$> rawVerbatimBlock
1028+ return . B.rawBlock "html" <$> rawVerbatimBlock
10291029 <|> (do guardEnabled Ext_markdown_attribute
10301030 oldMarkdownAttribute <- stateMarkdownAttribute <$> getState
10311031 markdownAttribute <-
@@ -1582,7 +1582,7 @@ ender c n = try $ do
15821582three :: PandocMonad m => Char -> MarkdownParser m (F Inlines)
15831583three c = do
15841584 contents <- mconcat <$> many (notFollowedBy (ender c 1) >> inline)
1585− (ender c 3 >> updateLastStrPos >> return ((B.strong . B.emph) <$> contents))
1585+ (ender c 3 >> updateLastStrPos >> return (B.strong . B.emph <$> contents))
15861586 <|> (ender c 2 >> updateLastStrPos >> one c (B.strong <$> contents))
15871587 <|> (ender c 1 >> updateLastStrPos >> two c (B.emph <$> contents))
15881588 <|> return (return (B.str $ T.pack [c,c,c]) <> contents)
@@ -1617,7 +1617,7 @@ inlinesBetween :: PandocMonad m
16171617 -> MarkdownParser m b
16181618 -> MarkdownParser m (F Inlines)
16191619inlinesBetween start end =
1620− (trimInlinesF . mconcat) <$> try (start >> many1Till inner end)
1620+ trimInlinesF . mconcat <$> try (start >> many1Till inner end)
16211621 where inner = innerSpace <|> (notFollowedBy' (() <$ whitespace) >> inline)
16221622 innerSpace = try $ whitespace <* notFollowedBy' end
16231623
@@ -1720,7 +1720,7 @@ source = do
17201720 try parenthesizedChars
17211721 <|> (notFollowedBy (oneOf " )") >> countChar 1 litChar)
17221722 <|> try (many1Char spaceChar <* notFollowedBy (oneOf "\"')"))
1723− let sourceURL = (T.unwords . T.words . T.concat) <$> many urlChunk
1723+ let sourceURL = T.unwords . T.words . T.concat <$> many urlChunk
17241724 let betweenAngles = try $
17251725 char '<' >> manyTillChar litChar (char '>')
17261726 src <- try betweenAngles <|> sourceURL
@@ -2023,7 +2023,7 @@ textualCite = try $ do
20232023 mbrest <- option Nothing $ try $ spnl >> Just <$> withRaw normalCite
20242024 case mbrest of
20252025 Just (rest, raw) ->
2026− return $ (flip B.cite (B.text $ "@" <> key <> " " <> raw) . (first:))
2026+ return $ flip B.cite (B.text $ "@" <> key <> " " <> raw) . (first:)
20272027 <$> rest
20282028 Nothing ->
20292029 (do
@@ -2130,4 +2130,4 @@ toRow :: [Blocks] -> Row
21302130toRow = Row nullAttr . map B.simpleCell
21312131
21322132toHeaderRow :: [Blocks] -> [Row]
2133−toHeaderRow l = if null l then [] else [toRow l]
2133+toHeaderRow l = [toRow l | not (null l)]
src/Text/Pandoc/Readers/MediaWiki.hs+3−3
@@ -231,7 +231,7 @@ table = do
231231 then (hdr, rows')
232232 else (replicate cols mempty, hdr:rows')
233233 let toRow = Row nullAttr . map B.simpleCell
234− toHeaderRow l = if null l then [] else [toRow l]
234+ toHeaderRow l = [toRow l | not (null l)]
235235 return $ B.table (B.simpleCaption $ B.plain caption)
236236 cellspecs
237237 (TableHead nullAttr $ toHeaderRow headers)
@@ -283,7 +283,7 @@ tableCaption = try $ do
283283 skipSpaces
284284 sym "|+"
285285 optional (try $ parseAttrs *> skipSpaces *> char '|' *> blanklines)
286− (trimInlines . mconcat) <$>
286+ trimInlines . mconcat <$>
287287 many (notFollowedBy (cellsep <|> rowsep) *> inline)
288288
289289tableRow :: PandocMonad m => MWParser m [((Alignment, Double), Blocks)]
@@ -678,7 +678,7 @@ url = do
678678-- | Parses a list of inlines between start and end delimiters.
679679inlinesBetween :: (PandocMonad m, Show b) => MWParser m a -> MWParser m b -> MWParser m Inlines
680680inlinesBetween start end =
681− (trimInlines . mconcat) <$> try (start >> many1Till inner end)
681+ trimInlines . mconcat <$> try (start >> many1Till inner end)
682682 where inner = innerSpace <|> (notFollowedBy' (() <$ whitespace) >> inline)
683683 innerSpace = try $ whitespace <* notFollowedBy' end
684684
src/Text/Pandoc/Readers/Muse.hs+1−1
@@ -653,7 +653,7 @@ museToPandocTable (MuseTable caption headers body footers) =
653653 where attrs = (AlignDefault, ColWidthDefault) <$ transpose (headers ++ body ++ footers)
654654 (headRow, rows) = fromMaybe ([], []) $ uncons headers
655655 toRow = Row nullAttr . map B.simpleCell
656− toHeaderRow l = if null l then [] else [toRow l]
656+ toHeaderRow l = [toRow l | not (null l)]
657657
658658museAppendElement :: MuseTableElement
659659 -> MuseTable
src/Text/Pandoc/Readers/Odt/ContentReader.hs+3−3
@@ -220,9 +220,9 @@ uniqueIdentFrom :: AnchorPrefix -> [Anchor] -> Anchor
220220uniqueIdentFrom baseIdent usedIdents =
221221 let numIdent n = baseIdent <> "-" <> T.pack (show n)
222222 in if baseIdent `elem` usedIdents
223− then case find (\x -> numIdent x `notElem` usedIdents) ([1..60000] :: [Int]) of
224− Just x -> numIdent x
225− Nothing -> baseIdent -- if we have more than 60,000, allow repeats
223+ then maybe baseIdent numIdent
224+ $ find (\x -> numIdent x `notElem` usedIdents) ([1..60000] :: [Int])
225+ -- if we have more than 60,000, allow repeats
226226 else baseIdent
227227
228228-- | First argument: basis for a new "pretty" anchor if none exists yet
src/Text/Pandoc/Readers/Odt/Generic/XMLConverter.hs+2−1
@@ -1,5 +1,6 @@
11{-# LANGUAGE TupleSections #-}
22{-# LANGUAGE GADTs #-}
3+{-# LANGUAGE LambdaCase #-}
34{-# LANGUAGE PatternGuards #-}
45{- |
56 Module : Text.Pandoc.Readers.Odt.Generic.XMLConverter
@@ -691,7 +692,7 @@ makeMatcherC nsID name c = ( second ( contentToElem
691692 >>% recover)
692693 &&&^ snd
693694 contentToElem :: FallibleXMLConverter nsID extraState XML.Content XML.Element
694− contentToElem = arr $ \e -> case e of
695+ contentToElem = arr $ \case
695696 XML.Elem e' -> succeedWith e'
696697 _ -> failEmpty
697698
src/Text/Pandoc/Readers/Org/Blocks.hs+11−12
@@ -34,6 +34,7 @@ import Text.Pandoc.Shared (compactify, compactifyDL, safeRead)
3434import Control.Monad (foldM, guard, mplus, mzero, void)
3535import Data.Char (isSpace)
3636import Data.Default (Default)
37+import Data.Functor (($>))
3738import Data.List (foldl', intersperse)
3839import Data.Maybe (fromMaybe, isJust, isNothing)
3940import Data.Text (Text)
@@ -103,9 +104,7 @@ attrFromBlockAttributes :: BlockAttributes -> Attr
103104attrFromBlockAttributes BlockAttributes{..} =
104105 let
105106 ident = fromMaybe mempty $ lookup "id" blockAttrKeyValues
106− classes = case lookup "class" blockAttrKeyValues of
107− Nothing -> []
108− Just clsStr -> T.words clsStr
107+ classes = maybe [] T.words $ lookup "class" blockAttrKeyValues
109108 kv = filter ((`notElem` ["id", "class"]) . fst) blockAttrKeyValues
110109 in (ident, classes, kv)
111110
@@ -576,10 +575,10 @@ rawExportLine = try $ do
576575rawOrgLine :: PandocMonad m => OrgParser m (F Blocks)
577576rawOrgLine = do
578577 line <- metaLineStart *> anyLine
579− returnF $ B.rawBlock "org" $ ("#+" <> line)
578+ returnF $ B.rawBlock "org" $ "#+" <> line
580579
581580commentLine :: Monad m => OrgParser m Blocks
582−commentLine = commentLineStart *> anyLine *> pure mempty
581+commentLine = commentLineStart *> anyLine $> mempty
583582
584583
585584--
@@ -648,12 +647,12 @@ orgToPandocTable (OrgTable colProps heads lns) caption =
648647 (TableFoot nullAttr [])
649648 where
650649 toRow = Row nullAttr . map B.simpleCell
651− toHeaderRow l = if null l then [] else [toRow l]
650+ toHeaderRow l = [toRow l | not (null l)]
652651 convertColProp :: Maybe Int -> ColumnProperty -> (Alignment, ColWidth)
653652 convertColProp totalWidth colProp =
654653 let
655654 align' = fromMaybe AlignDefault $ columnAlignment colProp
656− width' = (\w t -> (fromIntegral w / fromIntegral t))
655+ width' = (\w t -> fromIntegral w / fromIntegral t)
657656 <$> columnRelWidth colProp
658657 <*> totalWidth
659658 in (align', maybe ColWidthDefault ColWidth width')
@@ -691,9 +690,9 @@ columnPropertyCell = emptyOrgCell <|> propCell <?> "alignment info"
691690
692691tableAlignFromChar :: Monad m => OrgParser m Alignment
693692tableAlignFromChar = try $
694− choice [ char 'l' *> return AlignLeft
695− , char 'c' *> return AlignCenter
696− , char 'r' *> return AlignRight
693+ choice [ char 'l' $> AlignLeft
694+ , char 'c' $> AlignCenter
695+ , char 'r' $> AlignRight
697696 ]
698697
699698tableHline :: Monad m => OrgParser m OrgTableRow
@@ -796,13 +795,13 @@ paraOrPlain = try $ do
796795 -- Make sure we are not looking at a headline
797796 notFollowedBy' headerStart
798797 ils <- inlines
799− nl <- option False (newline *> return True)
798+ nl <- option False (newline $> True)
800799 -- Read block as paragraph, except if we are in a list context and the block
801800 -- is directly followed by a list item, in which case the block is read as
802801 -- plain text.
803802 try (guard nl
804803 *> notFollowedBy (inList *> (orderedListStart <|> bulletListStart))
805− *> return (B.para <$> ils))
804+ $> (B.para <$> ils))
806805 <|> return (B.plain <$> ils)
807806
808807
src/Text/Pandoc/Readers/Org/ParserState.hs+1−1
@@ -122,7 +122,7 @@ data OrgParserState = OrgParserState
122122 , orgMacros :: M.Map Text Macro
123123 }
124124
125−data OrgParserLocal = OrgParserLocal
125+newtype OrgParserLocal = OrgParserLocal
126126 { orgLocalQuoteContext :: QuoteContext
127127 }
128128
src/Text/Pandoc/Readers/Org/Shared.hs+1−3
@@ -58,9 +58,7 @@ cleanLinkText s
5858originalLang :: Text -> [(Text, Text)]
5959originalLang lang =
6060 let transLang = translateLang lang
61− in if transLang == lang
62− then []
63− else [("org-language", lang)]
61+ in [("org-language", lang) | transLang /= lang]
6462
6563-- | Translate from Org-mode's programming language identifiers to those used
6664-- by Pandoc. This is useful to allow for proper syntax highlighting in
src/Text/Pandoc/Readers/RST.hs+4−4
@@ -164,7 +164,7 @@ parseRST = do
164164 , stateIdentifiers = mempty }
165165 -- now parse it for real...
166166 blocks <- B.toList <$> parseBlocks
167− citations <- (sort . M.toList . stateCitations) <$> getState
167+ citations <- sort . M.toList . stateCitations <$> getState
168168 citationItems <- mapM parseCitation citations
169169 let refBlock = [Div ("citations",[],[]) $
170170 B.toList $ B.definitionList citationItems | not (null citationItems)]
@@ -823,7 +823,7 @@ listTableDirective top fields body = do
823823 splitTextBy (`elem` (" ," :: String)) specs
824824 _ -> replicate numOfCols ColWidthDefault
825825 toRow = Row nullAttr . map B.simpleCell
826− toHeaderRow l = if null l then [] else [toRow l]
826+ toHeaderRow l = [toRow l | not (null l)]
827827 return $ B.table (B.simpleCaption $ B.plain title)
828828 (zip (replicate numOfCols AlignDefault) widths)
829829 (TableHead nullAttr $ toHeaderRow headerRow)
@@ -906,7 +906,7 @@ csvTableDirective top fields rawcsv = do
906906 $ splitTextBy (`elem` (" ," :: String)) specs
907907 _ -> replicate numOfCols ColWidthDefault
908908 let toRow = Row nullAttr . map B.simpleCell
909− toHeaderRow l = if null l then [] else [toRow l]
909+ toHeaderRow l = [toRow l | not (null l)]
910910 return $ B.table (B.simpleCaption $ B.plain title)
911911 (zip (replicate numOfCols AlignDefault) widths)
912912 (TableHead nullAttr $ toHeaderRow headerRow)
@@ -1014,7 +1014,7 @@ toChunks = dropWhile T.null
10141014
10151015codeblock :: Text -> [Text] -> [(Text, Text)] -> Text -> Text -> Bool
10161016 -> RSTParser m Blocks
1017−codeblock ident classes fields lang body rmTrailingNewlines = do
1017+codeblock ident classes fields lang body rmTrailingNewlines =
10181018 return $ B.codeBlockWith attribs $ stripTrailingNewlines' body
10191019 where stripTrailingNewlines' = if rmTrailingNewlines
10201020 then stripTrailingNewlines
src/Text/Pandoc/Readers/TWiki.hs+7−7
@@ -214,7 +214,7 @@ listItemLine prefix marker = mconcat <$> (lineContent >>= parseContent)
214214 listContinuation = notFollowedBy (textStr prefix >> marker) >>
215215 string " " >> lineContent
216216 parseContent = parseFromString' $ many1 $ nestedList <|> parseInline
217− parseInline = (B.plain . mconcat) <$> many1Till inline (lastNewline <|> newlineBeforeNestedList)
217+ parseInline = B.plain . mconcat <$> many1Till inline (lastNewline <|> newlineBeforeNestedList)
218218 nestedList = list prefix
219219 lastNewline = try $ char '\n' <* eof
220220 newlineBeforeNestedList = try $ char '\n' <* lookAhead nestedList
@@ -235,7 +235,7 @@ table = try $ do
235235 columns rows = replicate (columCount rows) mempty
236236 columCount rows = length $ head rows
237237 toRow = Row nullAttr . map B.simpleCell
238− toHeaderRow l = if null l then [] else [toRow l]
238+ toHeaderRow l = [toRow l | not (null l)]
239239
240240tableParseHeader :: PandocMonad m => TWParser m ((Alignment, ColWidth), B.Blocks)
241241tableParseHeader = try $ do
@@ -265,13 +265,13 @@ tableEndOfRow :: PandocMonad m => TWParser m Char
265265tableEndOfRow = lookAhead (try $ char '|' >> char '\n') >> char '|'
266266
267267tableColumnContent :: PandocMonad m => TWParser m a -> TWParser m B.Blocks
268−tableColumnContent end = (B.plain . mconcat) <$> manyTill content (lookAhead $ try end)
268+tableColumnContent end = B.plain . mconcat <$> manyTill content (lookAhead $ try end)
269269 where
270270 content = continuation <|> inline
271271 continuation = try $ char '\\' >> newline >> return mempty
272272
273273blockQuote :: PandocMonad m => TWParser m B.Blocks
274−blockQuote = (B.blockQuote . mconcat) <$> parseHtmlContent "blockquote" block
274+blockQuote = B.blockQuote . mconcat <$> parseHtmlContent "blockquote" block
275275
276276noautolink :: PandocMonad m => TWParser m B.Blocks
277277noautolink = do
@@ -285,7 +285,7 @@ noautolink = do
285285 parseContent = parseFromString' $ many block
286286
287287para :: PandocMonad m => TWParser m B.Blocks
288−para = (result . mconcat) <$> many1Till inline endOfParaElement
288+para = result . mconcat <$> many1Till inline endOfParaElement
289289 where
290290 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
291291 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
@@ -428,13 +428,13 @@ nestedString end = innerSpace <|> countChar 1 nonspaceChar
428428 innerSpace = try $ many1Char spaceChar <* notFollowedBy end
429429
430430boldCode :: PandocMonad m => TWParser m B.Inlines
431−boldCode = try $ (B.strong . B.code . fromEntities) <$> enclosed (string "==") nestedString
431+boldCode = try $ B.strong . B.code . fromEntities <$> enclosed (string "==") nestedString
432432
433433htmlComment :: PandocMonad m => TWParser m B.Inlines
434434htmlComment = htmlTag isCommentTag >> return mempty
435435
436436code :: PandocMonad m => TWParser m B.Inlines
437−code = try $ (B.code . fromEntities) <$> enclosed (char '=') nestedString
437+code = try $ B.code . fromEntities <$> enclosed (char '=') nestedString
438438
439439codeHtml :: PandocMonad m => TWParser m B.Inlines
440440codeHtml = do
src/Text/Pandoc/Readers/Textile.hs+3−3
@@ -282,7 +282,7 @@ definitionListStart = try $ do
282282-- break.
283283definitionListItem :: PandocMonad m => ParserT Text ParserState m (Inlines, [Blocks])
284284definitionListItem = try $ do
285− term <- (mconcat . intersperse B.linebreak) <$> many1 definitionListStart
285+ term <- mconcat . intersperse B.linebreak <$> many1 definitionListStart
286286 def' <- string ":=" *> optional whitespace *> (multilineDef <|> inlineDef)
287287 return (term, def')
288288 where inlineDef :: PandocMonad m => ParserT Text ParserState m [Blocks]
@@ -378,7 +378,7 @@ table = try $ do
378378 let nbOfCols = maximum $ map length (headers:rows)
379379 let aligns = map minimum $ transpose $ map (map (snd . fst)) (headers:rows)
380380 let toRow = Row nullAttr . map B.simpleCell
381− toHeaderRow l = if null l then [] else [toRow l]
381+ toHeaderRow l = [toRow l | not (null l)]
382382 return $ B.table (B.simpleCaption $ B.plain caption)
383383 (zip aligns (replicate nbOfCols ColWidthDefault))
384384 (TableHead nullAttr $ toHeaderRow $ map snd headers)
@@ -439,7 +439,7 @@ inlineParsers = [ str
439439 , link
440440 , image
441441 , mark
442− , (B.str . T.singleton) <$> characterReference
442+ , B.str . T.singleton <$> characterReference
443443 , smartPunctuation inline
444444 , symbol
445445 ]
src/Text/Pandoc/Readers/Txt2Tags.hs+1−1
@@ -267,7 +267,7 @@ table = try $ do
267267 let rowsPadded = map (pad size) rows'
268268 let headerPadded = if null tableHeader then mempty else pad size tableHeader
269269 let toRow = Row nullAttr . map B.simpleCell
270− toHeaderRow l = if null l then [] else [toRow l]
270+ toHeaderRow l = [toRow l | not (null l)]
271271 return $ B.table B.emptyCaption
272272 (zip aligns (replicate ncolumns ColWidthDefault))
273273 (TableHead nullAttr $ toHeaderRow headerPadded)
src/Text/Pandoc/Shared.hs+4−6
@@ -580,7 +580,7 @@ makeSections numbering mbBaseLevel bs =
580580 let kvs' = -- don't touch number if already present
581581 case lookup "number" kvs of
582582 Nothing | numbering
583− , not ("unnumbered" `elem` classes) ->
583+ , "unnumbered" `notElem` classes ->
584584 ("number", T.intercalate "." (map tshow newnum)) : kvs
585585 _ -> kvs
586586 let divattr = (ident, "section":classes, kvs')
@@ -626,11 +626,9 @@ headerLtEq _ _ = False
626626uniqueIdent :: Extensions -> [Inline] -> Set.Set T.Text -> T.Text
627627uniqueIdent exts title' usedIdents =
628628 if baseIdent `Set.member` usedIdents
629− then case find (\x -> numIdent x `Set.notMember` usedIdents)
630− ([1..60000] :: [Int]) of
631− Just x -> numIdent x
632− Nothing -> baseIdent
633− -- if we have more than 60,000, allow repeats
629+ then maybe baseIdent numIdent
630+ $ find (\x -> numIdent x `Set.notMember` usedIdents) ([1..60000] :: [Int])
631+ -- if we have more than 60,000, allow repeats
634632 else baseIdent
635633 where
636634 baseIdent = case inlineListToIdentifier exts title' of
src/Text/Pandoc/Writers/CommonMark.hs−2
@@ -1,5 +1,3 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE ViewPatterns #-}
31{- |
42 Module : Text.Pandoc.Writers.CommonMark
53 Copyright : Copyright (C) 2015-2020 John MacFarlane
src/Text/Pandoc/Writers/ConTeXt.hs+3−3
@@ -209,7 +209,7 @@ blockToConTeXt (Div (ident,_,kvs) bs) = do
209209 <> literal lng <> "]" $$ txt $$ "\\stop"
210210 Nothing -> txt
211211 wrapBlank txt = blankline <> txt <> blankline
212− (wrapBlank . wrapLang . wrapDir . wrapRef) <$> blockListToConTeXt bs
212+ wrapBlank . wrapLang . wrapDir . wrapRef <$> blockListToConTeXt bs
213213blockToConTeXt (BulletList lst) = do
214214 contents <- mapM listItemToConTeXt lst
215215 return $ ("\\startitemize" <> if isTightList lst
@@ -332,7 +332,7 @@ alignToConTeXt align = case align of
332332 AlignDefault -> empty
333333
334334listItemToConTeXt :: PandocMonad m => [Block] -> WM m (Doc Text)
335−listItemToConTeXt list = (("\\item" $$) . nest 2) <$> blockListToConTeXt list
335+listItemToConTeXt list = ("\\item" $$) . nest 2 <$> blockListToConTeXt list
336336
337337defListItemToConTeXt :: PandocMonad m => ([Inline], [[Block]]) -> WM m (Doc Text)
338338defListItemToConTeXt (term, defs) = do
@@ -487,7 +487,7 @@ inlineToConTeXt (Span (_,_,kvs) ils) = do
487487 Just lng -> braces ("\\language" <>
488488 brackets (literal lng) <> txt)
489489 Nothing -> txt
490− (wrapLang . wrapDir) <$> inlineListToConTeXt ils
490+ wrapLang . wrapDir <$> inlineListToConTeXt ils
491491
492492-- | Craft the section header, inserting the section reference, if supplied.
493493sectionHeader :: PandocMonad m
src/Text/Pandoc/Writers/Docbook.hs+5−5
@@ -179,7 +179,7 @@ blockToDocbook opts (Div (id',"section":_,_) (Header lvl _ ils : xs)) = do
179179blockToDocbook opts (Div (ident,_,_) [Para lst]) =
180180 let attribs = [("id", ident) | not (T.null ident)] in
181181 if hasLineBreaks lst
182− then (flush . nowrap . inTags False "literallayout" attribs)
182+ then flush . nowrap . inTags False "literallayout" attribs
183183 <$> inlinesToDocbook opts lst
184184 else inTags True "para" attribs <$> inlinesToDocbook opts lst
185185blockToDocbook opts (Div (ident,_,_) bs) = do
@@ -206,7 +206,7 @@ blockToDocbook opts (Para [Image attr txt (src,T.stripPrefix "fig:" -> Just _)])
206206 (imageToDocbook opts attr src) $$
207207 inTagsSimple "textobject" (inTagsSimple "phrase" alt))
208208blockToDocbook opts (Para lst)
209− | hasLineBreaks lst = (flush . nowrap . inTagsSimple "literallayout")
209+ | hasLineBreaks lst = flush . nowrap . inTagsSimple "literallayout"
210210 <$> inlinesToDocbook opts lst
211211 | otherwise = inTagsIndented "para" <$> inlinesToDocbook opts lst
212212blockToDocbook opts (LineBlock lns) =
@@ -277,7 +277,7 @@ blockToDocbook opts (Table _ blkCapt specs thead tbody tfoot) = do
277277 head' <- if all null headers
278278 then return empty
279279 else inTagsIndented "thead" <$> tableRowToDocbook opts headers
280− body' <- (inTagsIndented "tbody" . vcat) <$>
280+ body' <- inTagsIndented "tbody" . vcat <$>
281281 mapM (tableRowToDocbook opts) rows
282282 return $ inTagsIndented tableType $ captionDoc $$
283283 inTags True "tgroup" [("cols", tshow (length aligns))] (
@@ -305,14 +305,14 @@ tableRowToDocbook :: PandocMonad m
305305 -> [[Block]]
306306 -> DB m (Doc Text)
307307tableRowToDocbook opts cols =
308− (inTagsIndented "row" . vcat) <$> mapM (tableItemToDocbook opts) cols
308+ inTagsIndented "row" . vcat <$> mapM (tableItemToDocbook opts) cols
309309
310310tableItemToDocbook :: PandocMonad m
311311 => WriterOptions
312312 -> [Block]
313313 -> DB m (Doc Text)
314314tableItemToDocbook opts item =
315− (inTags True "entry" [] . vcat) <$> mapM (blockToDocbook opts) item
315+ inTags True "entry" [] . vcat <$> mapM (blockToDocbook opts) item
316316
317317-- | Convert a list of inline elements to Docbook.
318318inlinesToDocbook :: PandocMonad m => WriterOptions -> [Inline] -> DB m (Doc Text)
src/Text/Pandoc/Writers/Docx.hs+1−1
@@ -1030,7 +1030,7 @@ blockToOpenXML' opts (Table _ blkCapt specs thead tbody tfoot) = do
10301030 let rowwidth = fullrow * sum widths
10311031 let mkgridcol w = mknode "w:gridCol"
10321032 [("w:w", show (floor (textwidth * w) :: Integer))] ()
1033− let hasHeader = any (not . null) headers
1033+ let hasHeader = not $ all null headers
10341034 modify $ \s -> s { stInTable = False }
10351035 return $
10361036 caption' ++
src/Text/Pandoc/Writers/EPUB.hs+12−14
@@ -62,7 +62,7 @@ import Text.DocTemplates (FromContext(lookupContext), Context(..),
6262 ToContext(toVal), Val(..))
6363
6464-- A Chapter includes a list of blocks.
65−data Chapter = Chapter [Block]
65+newtype Chapter = Chapter [Block]
6666 deriving (Show)
6767
6868data EPUBState = EPUBState {
@@ -711,10 +711,10 @@ pandocToEPUB version opts doc = do
711711 | writerTableOfContents opts ] ++
712712 map chapterRefNode chapterEntries)
713713 , unode "guide" $
714− [ unode "reference" !
715− [("type","toc"),("title", tocTitle),
716− ("href","nav.xhtml")] $ ()
717− ] ++
714+ (unode "reference" !
715+ [("type","toc"),("title", tocTitle),
716+ ("href","nav.xhtml")] $ ()
717+ ) :
718718 [ unode "reference" !
719719 [("type","cover")
720720 ,("title","Cover")
@@ -838,14 +838,12 @@ pandocToEPUB version opts doc = do
838838 ] | writerTableOfContents opts
839839 ]
840840 else []
841− let landmarks = if null landmarkItems
842− then []
843− else [RawBlock (Format "html") $ TS.pack $ ppElement $
844− unode "nav" ! [("epub:type","landmarks")
845− ,("id","landmarks")
846− ,("hidden","hidden")] $
847− [ unode "ol" landmarkItems ]
848− ]
841+ let landmarks = [RawBlock (Format "html") $ TS.pack $ ppElement $
842+ unode "nav" ! [("epub:type","landmarks")
843+ ,("id","landmarks")
844+ ,("hidden","hidden")] $
845+ [ unode "ol" landmarkItems ]
846+ | not (null landmarkItems)]
849847 navData <- lift $ writeHtml opts'{ writerVariables =
850848 Context (M.fromList [("navpage", toVal' "true")])
851849 <> cssvars False <> vars }
@@ -940,7 +938,7 @@ metadataElement version md currentTime =
940938 | version == EPUB2 = [dcNode "identifier" !
941939 (("id",id') : maybe [] (\x -> [("opf:scheme", x)]) scheme) $
942940 txt]
943− | otherwise = [dcNode "identifier" ! [("id",id')] $ txt] ++
941+ | otherwise = (dcNode "identifier" ! [("id",id')] $ txt) :
944942 maybe [] ((\x -> [unode "meta" !
945943 [ ("refines",'#':id')
946944 , ("property","identifier-type")
src/Text/Pandoc/Writers/HTML.hs+1−2
@@ -1,4 +1,3 @@
1−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
21{-# LANGUAGE LambdaCase #-}
32{-# LANGUAGE MultiWayIf #-}
43{-# LANGUAGE OverloadedStrings #-}
@@ -1025,7 +1024,7 @@ rowListToHtml :: PandocMonad m
10251024 -> [TableRow]
10261025 -> StateT WriterState m Html
10271026rowListToHtml opts rows =
1028− (\x -> (nl opts *> mconcat x)) <$>
1027+ (\x -> nl opts *> mconcat x) <$>
10291028 mapM (tableRowToHtml opts) rows
10301029
10311030colSpecListToHtml :: PandocMonad m
src/Text/Pandoc/Writers/Haddock.hs+1−1
@@ -28,7 +28,7 @@ import Text.Pandoc.Templates (renderTemplate)
2828import Text.Pandoc.Writers.Shared
2929
3030type Notes = [[Block]]
31−data WriterState = WriterState { stNotes :: Notes }
31+newtype WriterState = WriterState { stNotes :: Notes }
3232instance Default WriterState
3333 where def = WriterState{ stNotes = [] }
3434
src/Text/Pandoc/Writers/JATS.hs+5−5
@@ -216,7 +216,7 @@ imageMimeType src kvs =
216216 (T.takeWhile (/='/') <$> mbMT)
217217 subtype = fromMaybe "" $
218218 lookup "mime-subtype" kvs `mplus`
219− ((T.drop 1 . T.dropWhile (/='/')) <$> mbMT)
219+ (T.drop 1 . T.dropWhile (/='/') <$> mbMT)
220220 in (maintype, subtype)
221221
222222languageFor :: [Text] -> Text
@@ -372,7 +372,7 @@ blockToJATS opts (Table _ blkCapt specs th tb tf) =
372372 thead <- if all null headers
373373 then return empty
374374 else inTagsIndented "thead" <$> tableRowToJATS opts True headers
375− tbody <- (inTagsIndented "tbody" . vcat) <$>
375+ tbody <- inTagsIndented "tbody" . vcat <$>
376376 mapM (tableRowToJATS opts False) rows
377377 return $ inTags True "table" [] $ coltags $$ thead $$ tbody
378378
@@ -389,7 +389,7 @@ tableRowToJATS :: PandocMonad m
389389 -> [[Block]]
390390 -> JATS m (Doc Text)
391391tableRowToJATS opts isHeader cols =
392− (inTagsIndented "tr" . vcat) <$> mapM (tableItemToJATS opts isHeader) cols
392+ inTagsIndented "tr" . vcat <$> mapM (tableItemToJATS opts isHeader) cols
393393
394394tableItemToJATS :: PandocMonad m
395395 => WriterOptions
@@ -400,7 +400,7 @@ tableItemToJATS opts isHeader [Plain item] =
400400 inTags False (if isHeader then "th" else "td") [] <$>
401401 inlinesToJATS opts item
402402tableItemToJATS opts isHeader item =
403− (inTags False (if isHeader then "th" else "td") [] . vcat) <$>
403+ inTags False (if isHeader then "th" else "td") [] . vcat <$>
404404 mapM (blockToJATS opts) item
405405
406406-- | Convert a list of inline elements to JATS.
@@ -547,7 +547,7 @@ inlineToJATS _ (Image (ident,_,kvs) _ (src, tit)) = do
547547 (T.takeWhile (/='/') <$> mbMT)
548548 let subtype = fromMaybe "" $
549549 lookup "mime-subtype" kvs `mplus`
550− ((T.drop 1 . T.dropWhile (/='/')) <$> mbMT)
550+ (T.drop 1 . T.dropWhile (/='/') <$> mbMT)
551551 let attr = [("id", ident) | not (T.null ident)] ++
552552 [("mimetype", maintype),
553553 ("mime-subtype", subtype),
src/Text/Pandoc/Writers/LaTeX.hs+6−6
@@ -1049,7 +1049,7 @@ wrapDiv (_,classes,kvs) t = do
10491049 let valign = maybe "T" mapAlignment (lookup "align" kvs)
10501050 totalwidth = maybe [] (\x -> ["totalwidth=" <> x])
10511051 (lookup "totalwidth" kvs)
1052− onlytextwidth = filter ((==) "onlytextwidth") classes
1052+ onlytextwidth = filter ("onlytextwidth" ==) classes
10531053 options = text $ T.unpack $ T.intercalate "," $
10541054 valign : totalwidth ++ onlytextwidth
10551055 in inCmd "begin" "columns" <> brackets options
@@ -1458,8 +1458,8 @@ citeArgumentsList (CiteGroup _ _ []) = return empty
14581458citeArgumentsList (CiteGroup pfxs sfxs ids) = do
14591459 pdoc <- inlineListToLaTeX pfxs
14601460 sdoc <- inlineListToLaTeX sfxs'
1461− return $ (optargs pdoc sdoc) <>
1462− (braces (literal (T.intercalate "," (reverse ids))))
1461+ return $ optargs pdoc sdoc <>
1462+ braces (literal (T.intercalate "," (reverse ids)))
14631463 where sfxs' = stripLocatorBraces $ case sfxs of
14641464 (Str t : r) -> case T.uncons t of
14651465 Just (x, xs)
@@ -1516,12 +1516,12 @@ citationsToBiblatex (c:cs)
15161516
15171517 groups <- mapM citeArgumentsList (reverse (foldl' grouper [] (c:cs)))
15181518
1519− return $ text cmd <> (mconcat groups)
1519+ return $ text cmd <> mconcat groups
15201520
15211521 where grouper prev cit = case prev of
15221522 ((CiteGroup oPfx oSfx ids):rest)
1523− | null oSfx && null pfx -> (CiteGroup oPfx sfx (cid:ids)):rest
1524− _ -> (CiteGroup pfx sfx [cid]):prev
1523+ | null oSfx && null pfx -> CiteGroup oPfx sfx (cid:ids) : rest
1524+ _ -> CiteGroup pfx sfx [cid] : prev
15251525 where pfx = citationPrefix cit
15261526 sfx = citationSuffix cit
15271527 cid = citationId cit
src/Text/Pandoc/Writers/Man.hs+2−2
@@ -1,3 +1,4 @@
1+{-# LANGUAGE LambdaCase #-}
12{-# LANGUAGE OverloadedStrings #-}
23{-# LANGUAGE ViewPatterns #-}
34{- |
@@ -232,8 +233,7 @@ definitionListItemToMan opts (label, defs) = do
232233 labelText <- inlineListToMan opts $ makeCodeBold label
233234 contents <- if null defs
234235 then return empty
235− else liftM vcat $ forM defs $ \blocks ->
236− case blocks of
236+ else liftM vcat $ forM defs $ \case
237237 (x:xs) -> do
238238 first' <- blockToMan opts $
239239 case x of
src/Text/Pandoc/Writers/Markdown.hs+49−52
@@ -24,10 +24,9 @@ import Control.Monad.Reader
2424import Control.Monad.State.Strict
2525import Data.Char (isAlphaNum)
2626import Data.Default
27−import Data.List (find, intersperse, sortBy, transpose)
27+import Data.List (find, intersperse, sortOn, transpose)
2828import qualified Data.Map as M
2929import Data.Maybe (fromMaybe, mapMaybe)
30−import Data.Ord (comparing)
3130import qualified Data.Set as Set
3231import Data.Text (Text)
3332import qualified Data.Text as T
@@ -127,7 +126,7 @@ pandocTitleBlock tit auths dat =
127126
128127mmdTitleBlock :: Context Text -> Doc Text
129128mmdTitleBlock (Context hashmap) =
130− vcat $ map go $ sortBy (comparing fst) $ M.toList hashmap
129+ vcat $ map go $ sortOn fst $ M.toList hashmap
131130 where go (k,v) =
132131 case (text (T.unpack k), v) of
133132 (k', ListVal xs)
@@ -148,15 +147,15 @@ mmdTitleBlock (Context hashmap) =
148147plainTitleBlock :: Doc Text -> [Doc Text] -> Doc Text -> Doc Text
149148plainTitleBlock tit auths dat =
150149 tit <> cr <>
151− (hcat (intersperse (text "; ") auths)) <> cr <>
150+ hcat (intersperse (text "; ") auths) <> cr <>
152151 dat <> cr
153152
154153yamlMetadataBlock :: Context Text -> Doc Text
155−yamlMetadataBlock v = "---" $$ (contextToYaml v) $$ "---"
154+yamlMetadataBlock v = "---" $$ contextToYaml v $$ "---"
156155
157156contextToYaml :: Context Text -> Doc Text
158157contextToYaml (Context o) =
159− vcat $ map keyvalToYaml $ sortBy (comparing fst) $ M.toList o
158+ vcat $ map keyvalToYaml $ sortOn fst $ M.toList o
160159 where
161160 keyvalToYaml (k,v) =
162161 case (text (T.unpack k), v) of
@@ -250,7 +249,7 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
250249
251250-- | Return markdown representation of reference key table.
252251refsToMarkdown :: PandocMonad m => WriterOptions -> Refs -> MD m (Doc Text)
253−refsToMarkdown opts refs = mapM (keyToMarkdown opts) refs >>= return . vcat
252+refsToMarkdown opts refs = vcat <$> mapM (keyToMarkdown opts) refs
254253
255254-- | Return markdown representation of a reference key.
256255keyToMarkdown :: PandocMonad m
@@ -446,7 +445,7 @@ blockToMarkdown' opts (Plain inlines) = do
446445 then inlines
447446 else case inlines of
448447 (Str t:ys)
449− | (null ys || startsWithSpace ys)
448+ | null ys || startsWithSpace ys
450449 , beginsWithOrderedListMarker t
451450 -> RawInline (Format "markdown") (escapeMarker t):ys
452451 (Str t:_)
@@ -462,7 +461,7 @@ blockToMarkdown' opts (Para [Image attr alt (src,tgt@(T.stripPrefix "fig:" -> Ju
462461 | isEnabled Ext_raw_html opts &&
463462 not (isEnabled Ext_link_attributes opts) &&
464463 attr /= nullAttr = -- use raw HTML
465− ((<> blankline) . literal . T.strip) <$>
464+ (<> blankline) . literal . T.strip <$>
466465 writeHtml5String opts{ writerTemplate = Nothing }
467466 (Pandoc nullMeta [Para [Image attr alt (src,tgt)]])
468467 | otherwise = blockToMarkdown opts (Para [Image attr alt (src,tit)])
@@ -472,7 +471,7 @@ blockToMarkdown' opts (LineBlock lns) =
472471 if isEnabled Ext_line_blocks opts
473472 then do
474473 mdLines <- mapM (inlineListToMarkdown opts) lns
475− return $ (vcat $ map (hang 2 (literal "| ")) mdLines) <> blankline
474+ return $ vcat (map (hang 2 (literal "| ")) mdLines) <> blankline
476475 else blockToMarkdown opts $ linesToPara lns
477476blockToMarkdown' opts b@(RawBlock f str) = do
478477 variant <- asks envVariant
@@ -582,28 +581,28 @@ blockToMarkdown' opts (CodeBlock attribs str) = do
582581 attrs = if isEnabled Ext_fenced_code_attributes opts
583582 then nowrap $ " " <> attrsToMarkdown attribs
584583 else case attribs of
585− (_,(cls:_),_) -> " " <> literal cls
584+ (_,cls:_,_) -> " " <> literal cls
586585 _ -> empty
587586blockToMarkdown' opts (BlockQuote blocks) = do
588587 variant <- asks envVariant
589588 -- if we're writing literate haskell, put a space before the bird tracks
590589 -- so they won't be interpreted as lhs...
591− let leader = if isEnabled Ext_literate_haskell opts
592− then " > "
593− else if variant == PlainText then " " else "> "
590+ let leader
591+ | isEnabled Ext_literate_haskell opts = " > "
592+ | variant == PlainText = " "
593+ | otherwise = "> "
594594 contents <- blockListToMarkdown opts blocks
595− return $ (prefixed leader contents) <> blankline
595+ return $ prefixed leader contents <> blankline
596596blockToMarkdown' opts t@(Table _ blkCapt specs thead tbody tfoot) = do
597597 let (caption, aligns, widths, headers, rows) = toLegacyTable blkCapt specs thead tbody tfoot
598598 let numcols = maximum (length aligns : length widths :
599599 map length (headers:rows))
600600 caption' <- inlineListToMarkdown opts caption
601− let caption'' = if null caption
602− then blankline
603− else
604− if isEnabled Ext_table_captions opts
605− then blankline $$ (": " <> caption') $$ blankline
606− else blankline $$ caption' $$ blankline
601+ let caption''
602+ | null caption = blankline
603+ | isEnabled Ext_table_captions opts
604+ = blankline $$ (": " <> caption') $$ blankline
605+ | otherwise = blankline $$ caption' $$ blankline
607606 let hasSimpleCells = onlySimpleTableCells $ headers : rows
608607 let isSimple = hasSimpleCells && all (==0) widths
609608 let isPlainBlock (Plain _) = True
@@ -652,7 +651,7 @@ blockToMarkdown' opts t@(Table _ blkCapt specs thead tbody tfoot) = do
652651 (id,) <$> pipeTable (all null headers) aligns' rawHeaders rawRows
653652 | isEnabled Ext_raw_html opts -> fmap (id,) $
654653 literal <$>
655− (writeHtml5String opts{ writerTemplate = Nothing } $ Pandoc nullMeta [t])
654+ writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [t])
656655 | otherwise -> return (id, literal "[TABLE]")
657656 return $ nst (tbl $$ caption'') $$ blankline
658657blockToMarkdown' opts (BulletList items) = do
@@ -680,7 +679,7 @@ inList p = local (\env -> env {envInList = True}) p
680679addMarkdownAttribute :: Text -> Text
681680addMarkdownAttribute s =
682681 case span isTagText $ reverse $ parseTags s of
683− (xs,(TagOpen t attrs:rest)) ->
682+ (xs, TagOpen t attrs:rest) ->
684683 renderTags' $ reverse rest ++ (TagOpen t attrs' : reverse xs)
685684 where attrs' = ("markdown","1"):[(x,y) | (x,y) <- attrs,
686685 x /= "markdown"]
@@ -745,17 +744,16 @@ pandocTable opts multiline headless aligns widths rawHeaders rawRows = do
745744 | isSimple = map numChars columns
746745 | otherwise = zipWith relWidth widths columns
747746 let makeRow = hcat . intersperse (lblock 1 (literal " ")) .
748− (zipWith3 alignHeader aligns widthsInChars)
747+ zipWith3 alignHeader aligns widthsInChars
749748 let rows' = map makeRow rawRows
750749 let head' = makeRow rawHeaders
751750 let underline = mconcat $ intersperse (literal " ") $
752751 map (\width -> literal (T.replicate width "-")) widthsInChars
753− let border = if multiline
754− then literal (T.replicate (sum widthsInChars +
755− length widthsInChars - 1) "-")
756− else if headless
757− then underline
758− else empty
752+ let border
753+ | multiline = literal (T.replicate (sum widthsInChars +
754+ length widthsInChars - 1) "-")
755+ | headless = underline
756+ | otherwise = empty
759757 let head'' = if headless
760758 then empty
761759 else border <> cr <> head'
@@ -890,18 +888,17 @@ blockListToMarkdown opts blocks = do
890888 isListBlock (OrderedList _ _) = True
891889 isListBlock (DefinitionList _) = True
892890 isListBlock _ = False
893− commentSep = if variant == PlainText
894− then Null
895− else if isEnabled Ext_raw_html opts
896− then RawBlock "html" "<!-- -->\n"
897− else RawBlock "markdown" "&nbsp;\n"
898− mapM (blockToMarkdown opts) (fixBlocks blocks) >>= return . mconcat
891+ commentSep
892+ | variant == PlainText = Null
893+ | isEnabled Ext_raw_html opts = RawBlock "html" "<!-- -->\n"
894+ | otherwise = RawBlock "markdown" "&nbsp;\n"
895+ mconcat <$> mapM (blockToMarkdown opts) (fixBlocks blocks)
899896
900897getKey :: Doc Text -> Key
901898getKey = toKey . render Nothing
902899
903900findUsableIndex :: [Text] -> Int -> Int
904−findUsableIndex lbls i = if (tshow i) `elem` lbls
901+findUsableIndex lbls i = if tshow i `elem` lbls
905902 then findUsableIndex lbls (i + 1)
906903 else i
907904
@@ -973,19 +970,19 @@ inlineListToMarkdown opts lst = do
973970 go (if inlist then avoidBadWrapsInList lst else lst)
974971 where go [] = return empty
975972 go (i:is) = case i of
976− (Link _ _ _) -> case is of
973+ Link {} -> case is of
977974 -- If a link is followed by another link, or '[', '(' or ':'
978975 -- then we don't shortcut
979− (Link _ _ _):_ -> unshortcutable
980− Space:(Link _ _ _):_ -> unshortcutable
976+ Link {}:_ -> unshortcutable
977+ Space:Link {}:_ -> unshortcutable
981978 Space:(Str(thead -> Just '[')):_ -> unshortcutable
982979 Space:(RawInline _ (thead -> Just '[')):_ -> unshortcutable
983980 Space:(Cite _ _):_ -> unshortcutable
984− SoftBreak:(Link _ _ _):_ -> unshortcutable
981+ SoftBreak:Link {}:_ -> unshortcutable
985982 SoftBreak:(Str(thead -> Just '[')):_ -> unshortcutable
986983 SoftBreak:(RawInline _ (thead -> Just '[')):_ -> unshortcutable
987984 SoftBreak:(Cite _ _):_ -> unshortcutable
988− LineBreak:(Link _ _ _):_ -> unshortcutable
985+ LineBreak:Link {}:_ -> unshortcutable
989986 LineBreak:(Str(thead -> Just '[')):_ -> unshortcutable
990987 LineBreak:(RawInline _ (thead -> Just '[')):_ -> unshortcutable
991988 LineBreak:(Cite _ _):_ -> unshortcutable
@@ -1016,16 +1013,16 @@ avoidBadWrapsInList :: [Inline] -> [Inline]
10161013avoidBadWrapsInList [] = []
10171014avoidBadWrapsInList (s:Str (T.uncons -> Just ('>',cs)):xs) | isSp s =
10181015 Str (" >" <> cs) : avoidBadWrapsInList xs
1019−avoidBadWrapsInList (s:Str (T.uncons -> Just (c, cs)):[])
1020− | T.null cs && isSp s && c `elem` ['-','*','+'] = Str (T.pack [' ', c]) : []
1016+avoidBadWrapsInList [s, Str (T.uncons -> Just (c, cs))]
1017+ | T.null cs && isSp s && c `elem` ['-','*','+'] = [Str $ T.pack [' ', c]]
10211018avoidBadWrapsInList (s:Str (T.uncons -> Just (c, cs)):Space:xs)
10221019 | T.null cs && isSp s && c `elem` ['-','*','+'] =
10231020 Str (T.pack [' ', c]) : Space : avoidBadWrapsInList xs
10241021avoidBadWrapsInList (s:Str cs:Space:xs)
10251022 | isSp s && isOrderedListMarker cs =
10261023 Str (" " <> cs) : Space : avoidBadWrapsInList xs
1027−avoidBadWrapsInList (s:Str cs:[])
1028− | isSp s && isOrderedListMarker cs = Str (" " <> cs) : []
1024+avoidBadWrapsInList [s, Str cs]
1025+ | isSp s && isOrderedListMarker cs = [Str $ " " <> cs]
10291026avoidBadWrapsInList (x:xs) = x : avoidBadWrapsInList xs
10301027
10311028isOrderedListMarker :: Text -> Bool
@@ -1105,7 +1102,7 @@ inlineToMarkdown opts (Strikeout lst) = do
11051102 else contents
11061103inlineToMarkdown _ (Superscript []) = return empty
11071104inlineToMarkdown opts (Superscript lst) =
1108− local (\env -> env {envEscapeSpaces = (envVariant env == Markdown)}) $ do
1105+ local (\env -> env {envEscapeSpaces = envVariant env == Markdown}) $ do
11091106 contents <- inlineListToMarkdown opts lst
11101107 if isEnabled Ext_superscript opts
11111108 then return $ "^" <> contents <> "^"
@@ -1123,7 +1120,7 @@ inlineToMarkdown opts (Superscript lst) =
11231120 Nothing -> literal $ "^(" <> rendered <> ")"
11241121inlineToMarkdown _ (Subscript []) = return empty
11251122inlineToMarkdown opts (Subscript lst) =
1126− local (\env -> env {envEscapeSpaces = (envVariant env == Markdown)}) $ do
1123+ local (\env -> env {envEscapeSpaces = envVariant env == Markdown}) $ do
11271124 contents <- inlineListToMarkdown opts lst
11281125 if isEnabled Ext_subscript opts
11291126 then return $ "~" <> contents <> "~"
@@ -1167,7 +1164,7 @@ inlineToMarkdown opts (Code attr str) = do
11671164 then 0
11681165 else maximum $ map T.length tickGroups
11691166 let marker = T.replicate (longest + 1) "`"
1170− let spacer = if (longest == 0) then "" else " "
1167+ let spacer = if longest == 0 then "" else " "
11711168 let attrs = if isEnabled Ext_inline_code_attributes opts && attr /= nullAttr
11721169 then attrsToMarkdown attr
11731170 else empty
@@ -1296,7 +1293,7 @@ inlineToMarkdown opts lnk@(Link attr txt (src, tit))
12961293 | isEnabled Ext_raw_html opts &&
12971294 not (isEnabled Ext_link_attributes opts) &&
12981295 attr /= nullAttr = -- use raw HTML
1299− (literal . T.strip) <$>
1296+ literal . T.strip <$>
13001297 writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain [lnk]])
13011298 | otherwise = do
13021299 variant <- asks envVariant
@@ -1337,7 +1334,7 @@ inlineToMarkdown opts img@(Image attr alternate (source, tit))
13371334 | isEnabled Ext_raw_html opts &&
13381335 not (isEnabled Ext_link_attributes opts) &&
13391336 attr /= nullAttr = -- use raw HTML
1340− (literal . T.strip) <$>
1337+ literal . T.strip <$>
13411338 writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain [img]])
13421339 | otherwise = do
13431340 variant <- asks envVariant
@@ -1352,7 +1349,7 @@ inlineToMarkdown opts img@(Image attr alternate (source, tit))
13521349inlineToMarkdown opts (Note contents) = do
13531350 modify (\st -> st{ stNotes = contents : stNotes st })
13541351 st <- get
1355− let ref = literal $ writerIdentifierPrefix opts <> tshow (stNoteNum st + (length $ stNotes st) - 1)
1352+ let ref = literal $ writerIdentifierPrefix opts <> tshow (stNoteNum st + length (stNotes st) - 1)
13561353 if isEnabled Ext_footnotes opts
13571354 then return $ "[^" <> ref <> "]"
13581355 else return $ "[" <> ref <> "]"
src/Text/Pandoc/Writers/Ms.hs+2−4
@@ -67,9 +67,7 @@ pandocToMs opts (Pandoc meta blocks) = do
6767 let authorsMeta = map (escapeStr opts . stringify) $ docAuthors meta
6868 hasHighlighting <- gets stHighlighting
6969 let highlightingMacros = if hasHighlighting
70− then case writerHighlightStyle opts of
71− Nothing -> mempty
72− Just sty -> styleToMs sty
70+ then maybe mempty styleToMs $ writerHighlightStyle opts
7371 else mempty
7472
7573 let context = defField "body" main
@@ -523,7 +521,7 @@ msFormatter opts _fmtopts =
523521 where
524522 fmtLine = mconcat . map fmtToken
525523 fmtToken (toktype, tok) =
526− "\\*[" <> (tshow toktype) <> " \"" <> (escapeStr opts tok) <> "\"]"
524+ "\\*[" <> tshow toktype <> " \"" <> escapeStr opts tok <> "\"]"
527525
528526highlightCode :: PandocMonad m => WriterOptions -> Attr -> Text -> MS m (Doc Text)
529527highlightCode opts attr str =
src/Text/Pandoc/Writers/ODT.hs+1−1
@@ -71,7 +71,7 @@ pandocToODT opts doc@(Pandoc meta _) = do
7171 refArchive <-
7272 case writerReferenceDoc opts of
7373 Just f -> liftM toArchive $ lift $ P.readFileLazy f
74− Nothing -> lift $ (toArchive . B.fromStrict) <$>
74+ Nothing -> lift $ toArchive . B.fromStrict <$>
7575 P.readDataFile "reference.odt"
7676 -- handle formulas and pictures
7777 -- picEntriesRef <- P.newIORef ([] :: [Entry])
src/Text/Pandoc/Writers/OPML.hs+1−1
@@ -40,7 +40,7 @@ writeOPML opts (Pandoc meta blocks) = do
4040 writeMarkdown def (Pandoc nullMeta [Plain ils]))
4141 meta'
4242 let blocks' = makeSections False (Just 1) blocks
43− main <- (render colwidth . vcat) <$>
43+ main <- render colwidth . vcat <$>
4444 mapM (blockToOPML opts) blocks'
4545 let context = defField "body" main metadata
4646 return $
src/Text/Pandoc/Writers/OpenDocument.hs+1−1
@@ -387,7 +387,7 @@ blockToOpenDocument o bs
387387 r <- vcat <$> mapM (deflistItemToOpenDocument o) b
388388 setInDefinitionList False
389389 return r
390− preformatted s = (flush . vcat) <$> mapM (inPreformattedTags . escapeStringForXML) (T.lines s)
390+ preformatted s = flush . vcat <$> mapM (inPreformattedTags . escapeStringForXML) (T.lines s)
391391 mkBlockQuote b = do increaseIndent
392392 i <- paraStyle
393393 [("style:parent-style-name","Quotations")]
src/Text/Pandoc/Writers/Powerpoint/Output.hs+14−15
@@ -303,11 +303,11 @@ makeSpeakerNotesMap (Presentation _ slides) =
303303
304304presentationToArchive :: PandocMonad m => WriterOptions -> Presentation -> m Archive
305305presentationToArchive opts pres = do
306− distArchive <- (toArchive . BL.fromStrict) <$>
306+ distArchive <- toArchive . BL.fromStrict <$>
307307 P.readDefaultDataFile "reference.pptx"
308308 refArchive <- case writerReferenceDoc opts of
309309 Just f -> toArchive <$> P.readFileLazy f
310− Nothing -> (toArchive . BL.fromStrict) <$>
310+ Nothing -> toArchive . BL.fromStrict <$>
311311 P.readDataFile "reference.pptx"
312312
313313 utctime <- P.getCurrentTime
@@ -351,10 +351,10 @@ curSlideHasSpeakerNotes =
351351getLayout :: PandocMonad m => Layout -> P m Element
352352getLayout layout = do
353353 let layoutpath = case layout of
354− (MetadataSlide{}) -> "ppt/slideLayouts/slideLayout1.xml"
355− (TitleSlide _) -> "ppt/slideLayouts/slideLayout3.xml"
356− (ContentSlide _ _) -> "ppt/slideLayouts/slideLayout2.xml"
357− (TwoColumnSlide{}) -> "ppt/slideLayouts/slideLayout4.xml"
354+ MetadataSlide{} -> "ppt/slideLayouts/slideLayout1.xml"
355+ TitleSlide{} -> "ppt/slideLayouts/slideLayout3.xml"
356+ ContentSlide{} -> "ppt/slideLayouts/slideLayout2.xml"
357+ TwoColumnSlide{} -> "ppt/slideLayouts/slideLayout4.xml"
358358 refArchive <- asks envRefArchive
359359 distArchive <- asks envDistArchive
360360 parseXml refArchive distArchive layoutpath
@@ -547,7 +547,7 @@ registerMedia fp caption = do
547547
548548makeMediaEntry :: PandocMonad m => MediaInfo -> P m Entry
549549makeMediaEntry mInfo = do
550− epochtime <- (floor . utcTimeToPOSIXSeconds) <$> asks envUTCTime
550+ epochtime <- floor . utcTimeToPOSIXSeconds <$> asks envUTCTime
551551 (imgBytes, _) <- P.fetchItem (T.pack $ mInfoFilePath mInfo)
552552 let ext = fromMaybe "" (mInfoExt mInfo)
553553 let fp = "ppt/media/image" <>
@@ -1473,7 +1473,7 @@ presentationToRelsEntry pres = do
14731473
14741474elemToEntry :: PandocMonad m => FilePath -> Element -> P m Entry
14751475elemToEntry fp element = do
1476− epochtime <- (floor . utcTimeToPOSIXSeconds) <$> asks envUTCTime
1476+ epochtime <- floor . utcTimeToPOSIXSeconds <$> asks envUTCTime
14771477 return $ toEntry fp epochtime $ renderXml element
14781478
14791479slideToEntry :: PandocMonad m => Slide -> P m Entry
@@ -1500,8 +1500,7 @@ slideToSpeakerNotesEntry slide = do
15001500
15011501slideToSpeakerNotesRelElement :: PandocMonad m => Slide -> P m (Maybe Element)
15021502slideToSpeakerNotesRelElement (Slide _ _ (SpeakerNotes [])) = return Nothing
1503−slideToSpeakerNotesRelElement slide@(
1504− Slide{}) = do
1503+slideToSpeakerNotesRelElement slide@Slide{} = do
15051504 idNum <- slideNum slide
15061505 return $ Just $
15071506 mknode "Relationships"
@@ -1585,10 +1584,10 @@ slideToSlideRelElement :: PandocMonad m => Slide -> P m Element
15851584slideToSlideRelElement slide = do
15861585 idNum <- slideNum slide
15871586 let target = case slide of
1588− (Slide _ (MetadataSlide{}) _) -> "../slideLayouts/slideLayout1.xml"
1589− (Slide _ (TitleSlide _) _) -> "../slideLayouts/slideLayout3.xml"
1590− (Slide _ (ContentSlide _ _) _) -> "../slideLayouts/slideLayout2.xml"
1591− (Slide _ (TwoColumnSlide{}) _) -> "../slideLayouts/slideLayout4.xml"
1587+ (Slide _ MetadataSlide{} _) -> "../slideLayouts/slideLayout1.xml"
1588+ (Slide _ TitleSlide{} _) -> "../slideLayouts/slideLayout3.xml"
1589+ (Slide _ ContentSlide{} _) -> "../slideLayouts/slideLayout2.xml"
1590+ (Slide _ TwoColumnSlide{} _) -> "../slideLayouts/slideLayout4.xml"
15921591
15931592 speakerNotesRels <- maybeToList <$> speakerNotesSlideRelElement slide
15941593
@@ -1819,7 +1818,7 @@ getSpeakerNotesFilePaths = do
18191818
18201819presentationToContentTypes :: PandocMonad m => Presentation -> P m ContentTypes
18211820presentationToContentTypes p@(Presentation _ slides) = do
1822− mediaInfos <- (mconcat . M.elems) <$> gets stMediaIds
1821+ mediaInfos <- mconcat . M.elems <$> gets stMediaIds
18231822 filePaths <- patternsToFilePaths $ inheritedPatterns p
18241823 let mediaFps = filter (match (compile "ppt/media/image*")) filePaths
18251824 let defaults = [ DefaultContentType "xml" "application/xml"
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+4−4
@@ -537,10 +537,10 @@ withAttr _ sp = sp
537537blockToShape :: Block -> Pres Shape
538538blockToShape (Plain ils) = blockToShape (Para ils)
539539blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
540− (withAttr attr . Pic def (T.unpack url)) <$> inlinesToParElems ils
540+ withAttr attr . Pic def (T.unpack url) <$> inlinesToParElems ils
541541blockToShape (Para (il:_)) | Link _ (il':_) target <- il
542542 , Image attr ils (url, _) <- il' =
543− (withAttr attr . Pic def{picPropLink = Just $ ExternalTarget target} (T.unpack url))
543+ withAttr attr . Pic def{picPropLink = Just $ ExternalTarget target} (T.unpack url)
544544 <$> inlinesToParElems ils
545545blockToShape (Table _ blkCapt specs thead tbody tfoot) = do
546546 let (caption, algn, _, hdrCells, rows) = toLegacyTable blkCapt specs thead tbody tfoot
@@ -721,7 +721,7 @@ makeNoteEntry (n, blks) =
721721 let enum = Str (tshow n <> ".")
722722 in
723723 case blks of
724− (Para ils : blks') -> (Para $ enum : Space : ils) : blks'
724+ (Para ils : blks') -> Para (enum : Space : ils) : blks'
725725 _ -> Para [enum] : blks
726726
727727forceFontSize :: Pixels -> Pres a -> Pres a
@@ -767,7 +767,7 @@ getMetaSlide = do
767767 mempty
768768
769769addSpeakerNotesToMetaSlide :: Slide -> [Block] -> Pres (Slide, [Block])
770−addSpeakerNotesToMetaSlide (Slide sldId layout@(MetadataSlide{}) spkNotes) blks =
770+addSpeakerNotesToMetaSlide (Slide sldId layout@MetadataSlide{} spkNotes) blks =
771771 do let (ntsBlks, blks') = span isNotesDiv blks
772772 spkNotes' <- mconcat <$> mapM blockToSpeakerNotes ntsBlks
773773 return (Slide sldId layout (spkNotes <> spkNotes'), blks')
src/Text/Pandoc/Writers/RTF.hs+3−3
@@ -241,12 +241,12 @@ blockToRTF _ _ b@(RawBlock f str)
241241 | otherwise = do
242242 report $ BlockNotRendered b
243243 return ""
244−blockToRTF indent alignment (BulletList lst) = (spaceAtEnd . T.concat) <$>
244+blockToRTF indent alignment (BulletList lst) = spaceAtEnd . T.concat <$>
245245 mapM (listItemToRTF alignment indent (bulletMarker indent)) lst
246246blockToRTF indent alignment (OrderedList attribs lst) =
247− (spaceAtEnd . T.concat) <$>
247+ spaceAtEnd . T.concat <$>
248248 zipWithM (listItemToRTF alignment indent) (orderedMarkers indent attribs) lst
249−blockToRTF indent alignment (DefinitionList lst) = (spaceAtEnd . T.concat) <$>
249+blockToRTF indent alignment (DefinitionList lst) = spaceAtEnd . T.concat <$>
250250 mapM (definitionListItemToRTF alignment indent) lst
251251blockToRTF indent _ HorizontalRule = return $
252252 rtfPar indent 0 AlignCenter "\\emdash\\emdash\\emdash\\emdash\\emdash"
src/Text/Pandoc/Writers/TEI.hs+3−3
@@ -205,14 +205,14 @@ tableRowToTEI :: PandocMonad m
205205 -> [[Block]]
206206 -> m (Doc Text)
207207tableRowToTEI opts cols =
208− (inTagsIndented "row" . vcat) <$> mapM (tableItemToTEI opts) cols
208+ inTagsIndented "row" . vcat <$> mapM (tableItemToTEI opts) cols
209209
210210tableHeadersToTEI :: PandocMonad m
211211 => WriterOptions
212212 -> [[Block]]
213213 -> m (Doc Text)
214214tableHeadersToTEI opts cols =
215− (inTags True "row" [("role","label")] . vcat) <$>
215+ inTags True "row" [("role","label")] . vcat <$>
216216 mapM (tableItemToTEI opts) cols
217217
218218tableItemToTEI :: PandocMonad m
@@ -220,7 +220,7 @@ tableItemToTEI :: PandocMonad m
220220 -> [Block]
221221 -> m (Doc Text)
222222tableItemToTEI opts item =
223− (inTags False "cell" [] . vcat) <$> mapM (blockToTEI opts) item
223+ inTags False "cell" [] . vcat <$> mapM (blockToTEI opts) item
224224
225225-- | Convert a list of inline elements to TEI.
226226inlinesToTEI :: PandocMonad m => WriterOptions -> [Inline] -> m (Doc Text)
src/Text/Pandoc/Writers/XWiki.hs+1−1
@@ -45,7 +45,7 @@ import Text.Pandoc.Shared
4545import Text.Pandoc.Writers.MediaWiki (highlightingLangs)
4646import Text.Pandoc.Writers.Shared (toLegacyTable)
4747
48−data WriterState = WriterState {
48+newtype WriterState = WriterState {
4949 listLevel :: Text -- String at the beginning of items
5050}
5151
src/Text/Pandoc/XML.hs+2−1
@@ -1,3 +1,4 @@
1+{-# LANGUAGE LambdaCase #-}
12{-# LANGUAGE OverloadedStrings #-}
23{-# LANGUAGE ViewPatterns #-}
34{- |
@@ -54,7 +55,7 @@ escapeStringForXML = T.concatMap escapeCharForXML . T.filter isLegalXMLChar
5455
5556-- | Escape newline characters as &#10;
5657escapeNls :: Text -> Text
57−escapeNls = T.concatMap $ \x -> case x of
58+escapeNls = T.concatMap $ \case
5859 '\n' -> "&#10;"
5960 c -> T.singleton c
6061
test/Tests/Helpers.hs+1−2
@@ -1,7 +1,6 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE NoImplicitPrelude #-}
33{-# LANGUAGE FlexibleInstances #-}
4−{-# LANGUAGE TypeSynonymInstances #-}
54{- |
65 Module : Tests.Helpers
76 Copyright : © 2006-2020 John MacFarlane
@@ -104,7 +103,7 @@ findPandoc = do
104103 -- cabalv1
105104 "test-pandoc" : "build" : ps
106105 -> joinPath (reverse ps) </> "build" </> "pandoc"
107− _ -> error $ "findPandoc: could not find pandoc executable"
106+ _ -> error "findPandoc: could not find pandoc executable"
108107 let pandocPath = pandocDir </> "pandoc"
109108#ifdef _WINDOWS
110109 <.> "exe"
test/Tests/Old.hs+1−2
@@ -14,7 +14,6 @@ module Tests.Old (tests) where
1414
1515import Prelude
1616import Data.Algorithm.Diff
17−import Prelude hiding (readFile)
1817import Data.List (intercalate)
1918import Data.Maybe (catMaybes)
2019import System.Exit
@@ -291,7 +290,7 @@ fb2WriterTest pandocPath title opts inputfile normfile =
291290 where
292291 formatXML xml = splitTags $ zip xml (drop 1 xml)
293292 splitTags [] = []
294− splitTags [end] = fst end : snd end : []
293+ splitTags [end] = [fst end, snd end]
295294 splitTags (('>','<'):rest) = ">\n" ++ splitTags rest
296295 splitTags ((c,_):rest) = c : splitTags rest
297296 ignoreBinary = unlines . filter (not . startsWith "<binary ") . lines
test/Tests/Readers/Docx.hs+1−1
@@ -33,7 +33,7 @@ import Text.Pandoc.UTF8 as UTF8
3333-- tests. Since we do our own normalization, we want to make sure
3434-- we're doing it right.
3535
36−data NoNormPandoc = NoNormPandoc {unNoNorm :: Pandoc}
36+newtype NoNormPandoc = NoNormPandoc {unNoNorm :: Pandoc}
3737 deriving Show
3838
3939noNorm :: Pandoc -> NoNormPandoc
test/Tests/Readers/Man.hs+1−1
@@ -68,7 +68,7 @@ tests = [
6868 testGroup "Escapes" [
6969 "fonts" =:
7070 "aa\\fIbb\\fRcc"
71− =?>para (str "aa" <> (emph $ str "bb") <> str "cc")
71+ =?>para (str "aa" <> emph (str "bb") <> str "cc")
7272 , "nested fonts" =:
7373 "\\f[BI]hi\\f[I] there\\f[R]"
7474 =?> para (emph (strong (text "hi") <> text " there"))
test/Tests/Readers/Muse.hs+1−1
@@ -51,7 +51,7 @@ simpleTable' n capt headers rows
5151 (TableFoot nullAttr [])
5252 where
5353 toRow = Row nullAttr . map simpleCell
54− toHeaderRow l = if null l then [] else [toRow l]
54+ toHeaderRow l = [toRow l | not (null l)]
5555
5656-- Tables don't round-trip yet
5757--
test/Tests/Readers/Org/Block/Table.hs+1−1
@@ -35,7 +35,7 @@ simpleTable'' capt spec headers rows
3535 (TableFoot nullAttr [])
3636 where
3737 toRow = Row nullAttr . map simpleCell
38− toHeaderRow l = if null l then [] else [toRow l]
38+ toHeaderRow l = [toRow l | not (null l)]
3939
4040tests :: [TestTree]
4141tests =
test/Tests/Readers/Org/Directive.hs+1−1
@@ -30,7 +30,7 @@ testWithFiles :: (ToString c)
3030 -> (T.Text, c) -- ^ (input, expected value)
3131 -> TestTree
3232testWithFiles fileDefs = test (orgWithFiles fileDefs)
33− where
33+
3434orgWithFiles :: [(FilePath, BS.ByteString)] -> T.Text -> Pandoc
3535orgWithFiles fileDefs input =
3636 let readOrg' = readOrg def{ readerExtensions = getDefaultExtensions "org" }
test/Tests/Readers/Txt2Tags.hs+1−1
@@ -54,7 +54,7 @@ simpleTable'' spec headers rows
5454 (TableFoot nullAttr [])
5555 where
5656 toRow = Row nullAttr . map simpleCell
57− toHeaderRow l = if null l then [] else [toRow l]
57+ toHeaderRow l = [toRow l | not (null l)]
5858
5959tests :: [TestTree]
6060tests =
test/Tests/Shared.hs+18−18
@@ -35,24 +35,24 @@ tests = [ testGroup "compactifyDL"
3535
3636testCollapse :: [TestTree]
3737testCollapse = map (testCase "collapse")
38− [ collapseFilePath (joinPath [ ""]) @?= (joinPath [ ""])
39− , collapseFilePath (joinPath [ ".","foo"]) @?= (joinPath [ "foo"])
40− , collapseFilePath (joinPath [ ".",".","..","foo"]) @?= (joinPath [ joinPath ["..", "foo"]])
41− , collapseFilePath (joinPath [ "..","foo"]) @?= (joinPath [ "..","foo"])
42− , collapseFilePath (joinPath [ "","bar","..","baz"]) @?= (joinPath [ "","baz"])
43− , collapseFilePath (joinPath [ "","..","baz"]) @?= (joinPath [ "","..","baz"])
44− , collapseFilePath (joinPath [ ".","foo","..",".","bar","..",".",".","baz"]) @?= (joinPath [ "baz"])
45− , collapseFilePath (joinPath [ ".",""]) @?= (joinPath [ ""])
46− , collapseFilePath (joinPath [ ".",".",""]) @?= (joinPath [ ""])
47− , collapseFilePath (joinPath [ "..",""]) @?= (joinPath [ ".."])
48− , collapseFilePath (joinPath [ "..",".",""]) @?= (joinPath [ ".."])
49− , collapseFilePath (joinPath [ ".","..",""]) @?= (joinPath [ ".."])
50− , collapseFilePath (joinPath [ "..","..",""]) @?= (joinPath [ "..",".."])
51− , collapseFilePath (joinPath [ "parent","foo","baz","..","bar"]) @?= (joinPath [ "parent","foo","bar"])
52− , collapseFilePath (joinPath [ "parent","foo","baz","..","..","bar"]) @?= (joinPath [ "parent","bar"])
53− , collapseFilePath (joinPath [ "parent","foo",".."]) @?= (joinPath [ "parent"])
54− , collapseFilePath (joinPath [ "","parent","foo","..","..","bar"]) @?= (joinPath [ "","bar"])
55− , collapseFilePath (joinPath [ "",".","parent","foo"]) @?= (joinPath [ "","parent","foo"])]
38+ [ collapseFilePath (joinPath [ ""]) @?= joinPath [ ""]
39+ , collapseFilePath (joinPath [ ".","foo"]) @?= joinPath [ "foo"]
40+ , collapseFilePath (joinPath [ ".",".","..","foo"]) @?= joinPath [ joinPath ["..", "foo"]]
41+ , collapseFilePath (joinPath [ "..","foo"]) @?= joinPath [ "..","foo"]
42+ , collapseFilePath (joinPath [ "","bar","..","baz"]) @?= joinPath [ "","baz"]
43+ , collapseFilePath (joinPath [ "","..","baz"]) @?= joinPath [ "","..","baz"]
44+ , collapseFilePath (joinPath [ ".","foo","..",".","bar","..",".",".","baz"]) @?= joinPath [ "baz"]
45+ , collapseFilePath (joinPath [ ".",""]) @?= joinPath [ ""]
46+ , collapseFilePath (joinPath [ ".",".",""]) @?= joinPath [ ""]
47+ , collapseFilePath (joinPath [ "..",""]) @?= joinPath [ ".."]
48+ , collapseFilePath (joinPath [ "..",".",""]) @?= joinPath [ ".."]
49+ , collapseFilePath (joinPath [ ".","..",""]) @?= joinPath [ ".."]
50+ , collapseFilePath (joinPath [ "..","..",""]) @?= joinPath [ "..",".."]
51+ , collapseFilePath (joinPath [ "parent","foo","baz","..","bar"]) @?= joinPath [ "parent","foo","bar"]
52+ , collapseFilePath (joinPath [ "parent","foo","baz","..","..","bar"]) @?= joinPath [ "parent","bar"]
53+ , collapseFilePath (joinPath [ "parent","foo",".."]) @?= joinPath [ "parent"]
54+ , collapseFilePath (joinPath [ "","parent","foo","..","..","bar"]) @?= joinPath [ "","bar"]
55+ , collapseFilePath (joinPath [ "",".","parent","foo"]) @?= joinPath [ "","parent","foo"]]
5656
5757testLegacyTable :: [TestTree]
5858testLegacyTable =
test/Tests/Writers/OOXML.hs+1−1
@@ -48,7 +48,7 @@ displayDiff elemA elemB =
4848 showDiff (1,1) $ getDiff (lines $ ppContent elemA) (lines $ ppContent elemB)
4949
5050goldenArchive :: FilePath -> IO Archive
51−goldenArchive fp = (toArchive . BL.fromStrict) <$> BS.readFile fp
51+goldenArchive fp = toArchive . BL.fromStrict <$> BS.readFile fp
5252
5353testArchive :: (WriterOptions -> Pandoc -> PandocIO BL.ByteString)
5454 -> WriterOptions