@@ -45,7 +45,7 @@ import Text.Pandoc.Process (pipeProcess)
4545import Text.Highlighting.Kate ( languages, Style, tango, pygments,
4646 espresso, zenburn, kate, haddock, monochrome )
4747import System.Environment ( getArgs, getProgName )
48−import System.Exit ( exitWith, ExitCode (..) )
48+import System.Exit ( ExitCode (..), exitSuccess )
4949import System.FilePath
5050import System.Console.GetOpt
5151import Data.Char ( toLower )
@@ -58,7 +58,7 @@ import qualified Control.Exception as E
5858import Control.Exception.Extensible ( throwIO )
5959import qualified Text.Pandoc.UTF8 as UTF8
6060import Control.Monad (when, unless, (>=>))
61−import Data.Maybe (fromMaybe, isNothing)
61+import Data.Maybe (fromMaybe, isNothing, isJust)
6262import Data.Foldable (foldrM)
6363import Network.URI (parseURI, isURI, URI(..))
6464import qualified Data.ByteString.Lazy as B
@@ -149,7 +149,7 @@ externalFilter f args' d = do
149149 show f' ++ " not found in path."
150150 (exitcode, outbs, errbs) <- E.handle filterException $
151151 pipeProcess Nothing f' args'' $ encode d
152− when (not $ B.null errbs) $ B.hPutStr stderr errbs
152+ unless (B.null errbs) $ B.hPutStr stderr errbs
153153 case exitcode of
154154 ExitSuccess -> return $ either error id $ eitherDecode' outbs
155155 ExitFailure ec -> err 83 $ "Error running filter " ++ f ++ "\n" ++
@@ -398,7 +398,7 @@ options =
398398
399399 , Option "" ["extract-media"]
400400 (ReqArg
401− (\arg opt -> do
401+ (\arg opt ->
402402 return opt { optExtractMedia = Just arg })
403403 "PATH")
404404 "" -- "Directory to which to extract embedded media"
@@ -410,7 +410,7 @@ options =
410410
411411 , Option "" ["template"]
412412 (ReqArg
413− (\arg opt -> do
413+ (\arg opt ->
414414 return opt{ optTemplate = Just arg,
415415 optStandalone = True })
416416 "FILENAME")
@@ -444,7 +444,7 @@ options =
444444 case templ of
445445 Right t -> UTF8.hPutStr stdout t
446446 Left e -> error $ show e
447− exitWith ExitSuccess)
447+ exitSuccess)
448448 "FORMAT")
449449 "" -- "Print default template for FORMAT"
450450
@@ -452,7 +452,7 @@ options =
452452 (ReqArg
453453 (\arg _ -> do
454454 readDataFile Nothing arg >>= BS.hPutStr stdout
455− exitWith ExitSuccess)
455+ exitSuccess)
456456 "FILE")
457457 "" -- "Print default data file"
458458
@@ -476,7 +476,7 @@ options =
476476 (\arg opt ->
477477 case safeRead arg of
478478 Just t | t > 0 -> return opt { optColumns = t }
479− _ -> err 33 $
479+ _ -> err 33
480480 "columns must be a number greater than 0")
481481 "NUMBER")
482482 "" -- "Length of line in characters"
@@ -488,11 +488,11 @@ options =
488488
489489 , Option "" ["toc-depth"]
490490 (ReqArg
491− (\arg opt -> do
491+ (\arg opt ->
492492 case safeRead arg of
493493 Just t | t >= 1 && t <= 6 ->
494494 return opt { optTOCDepth = t }
495− _ -> err 57 $
495+ _ -> err 57
496496 "TOC level must be a number between 1 and 6")
497497 "NUMBER")
498498 "" -- "Number of levels to include in TOC"
@@ -560,7 +560,7 @@ options =
560560
561561 , Option "" ["offline"]
562562 (NoArg
563− (\opt -> do warn $ "--offline is deprecated. Use --self-contained instead."
563+ (\opt -> do warn "--offline is deprecated. Use --self-contained instead."
564564 return opt { optSelfContained = True,
565565 optStandalone = True }))
566566 "" -- "Make slide shows include all the needed js and css"
@@ -576,7 +576,7 @@ options =
576576
577577 , Option "" ["html-q-tags"]
578578 (NoArg
579− (\opt -> do
579+ (\opt ->
580580 return opt { optHtmlQTags = True }))
581581 "" -- "Use <q> tags for quotes in HTML"
582582
@@ -632,11 +632,11 @@ options =
632632
633633 , Option "" ["slide-level"]
634634 (ReqArg
635− (\arg opt -> do
635+ (\arg opt ->
636636 case safeRead arg of
637637 Just t | t >= 1 && t <= 6 ->
638638 return opt { optSlideLevel = Just t }
639− _ -> err 39 $
639+ _ -> err 39
640640 "slide level must be a number between 1 and 6")
641641 "NUMBER")
642642 "" -- "Force header level for slides"
@@ -692,14 +692,14 @@ options =
692692
693693 , Option "" ["reference-odt"]
694694 (ReqArg
695− (\arg opt -> do
695+ (\arg opt ->
696696 return opt { optReferenceODT = Just arg })
697697 "FILENAME")
698698 "" -- "Path of custom reference.odt"
699699
700700 , Option "" ["reference-docx"]
701701 (ReqArg
702− (\arg opt -> do
702+ (\arg opt ->
703703 return opt { optReferenceDocx = Just arg })
704704 "FILENAME")
705705 "" -- "Path of custom reference.docx"
@@ -730,18 +730,18 @@ options =
730730
731731 , Option "" ["epub-embed-font"]
732732 (ReqArg
733− (\arg opt -> do
733+ (\arg opt ->
734734 return opt{ optEpubFonts = arg : optEpubFonts opt })
735735 "FILE")
736736 "" -- "Directory of fonts to embed"
737737
738738 , Option "" ["epub-chapter-level"]
739739 (ReqArg
740− (\arg opt -> do
740+ (\arg opt ->
741741 case safeRead arg of
742742 Just t | t >= 1 && t <= 6 ->
743743 return opt { optEpubChapterLevel = t }
744− _ -> err 59 $
744+ _ -> err 59
745745 "chapter level must be a number between 1 and 6")
746746 "NUMBER")
747747 "" -- "Header level at which to split chapters in EPUB"
@@ -829,9 +829,7 @@ options =
829829 , Option "" ["webtex"]
830830 (OptArg
831831 (\arg opt -> do
832− let url' = case arg of
833− Just u -> u
834− Nothing -> "http://chart.apis.google.com/chart?cht=tx&chl="
832+ let url' = fromMaybe "http://chart.apis.google.com/chart?cht=tx&chl=" arg
835833 return opt { optHTMLMathMethod = WebTeX url' })
836834 "URL")
837835 "" -- "Use web service for HTML math"
@@ -845,9 +843,7 @@ options =
845843 , Option "" ["mathjax"]
846844 (OptArg
847845 (\arg opt -> do
848− let url' = case arg of
849− Just u -> u
850− Nothing -> "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
846+ let url' = fromMaybe "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" arg
851847 return opt { optHTMLMathMethod = MathJax url'})
852848 "URL")
853849 "" -- "Use MathJax for HTML math"
@@ -905,7 +901,7 @@ options =
905901 (unwords (map fst readers))
906902 (unwords ("pdf": map fst writers))
907903 ddir
908− exitWith ExitSuccess ))
904+ exitSuccess ))
909905 "" -- "Print bash completion script"
910906
911907 , Option "v" ["version"]
@@ -916,7 +912,7 @@ options =
916912 UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++
917913 compileInfo ++ "\nDefault user data directory: " ++
918914 defaultDatadir ++ copyrightMessage)
919− exitWith ExitSuccess ))
915+ exitSuccess ))
920916 "" -- "Print version"
921917
922918 , Option "h" ["help"]
@@ -924,7 +920,7 @@ options =
924920 (\_ -> do
925921 prg <- getProgName
926922 UTF8.hPutStr stdout (usageMessage prg options)
927− exitWith ExitSuccess ))
923+ exitSuccess ))
928924 "" -- "Show help"
929925
930926 ]
@@ -948,10 +944,10 @@ readMetaValue s = case decode (UTF8.fromString s) of
948944usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
949945usageMessage programName = usageInfo
950946 (programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
951− (wrapWords 16 78 $ readers'names) ++
947+ wrapWords 16 78 readers'names ++
952948 '\n' : replicate 16 ' ' ++
953949 "[ *only Pandoc's JSON version of native AST]" ++ "\nOutput formats: " ++
954− (wrapWords 16 78 $ writers'names) ++
950+ wrapWords 16 78 writers'names ++
955951 '\n' : replicate 16 ' ' ++
956952 "[**for pdf output, use latex or beamer and -o FILENAME.pdf]\nOptions:")
957953 where
@@ -1060,7 +1056,7 @@ main = do
10601056
10611057 rawArgs <- map UTF8.decodeArg <$> getArgs
10621058 prg <- getProgName
1063− let compatMode = (prg == "hsmarkdown")
1059+ let compatMode = prg == "hsmarkdown"
10641060
10651061 let (actions, args, errors) = if compatMode
10661062 then ([], rawArgs, [])
@@ -1142,8 +1138,8 @@ main = do
11421138
11431139 when dumpArgs $
11441140 do UTF8.hPutStrLn stdout outputFile
1145− mapM_ (\arg -> UTF8.hPutStrLn stdout arg) args
1146− exitWith ExitSuccess
1141+ mapM_ (UTF8.hPutStrLn stdout) args
1142+ exitSuccess
11471143
11481144 let csscdn = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css"
11491145 let mathMethod =
@@ -1153,7 +1149,7 @@ main = do
11531149
11541150
11551151 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
1156− let needsCiteproc = M.lookup "bibliography" (optMetadata opts) /= Nothing &&
1152+ let needsCiteproc = isJust (M.lookup "bibliography" (optMetadata opts)) &&
11571153 optCiteMethod opts `notElem` [Natbib, Biblatex] &&
11581154 "pandoc-citeproc" `notElem` map takeBaseName filters
11591155 let filters' = if needsCiteproc then "pandoc-citeproc" : filters
@@ -1209,7 +1205,7 @@ main = do
12091205 reader <- if "t2t" == readerName'
12101206 then (mkStringReader .
12111207 readTxt2Tags) <$>
1212− (getT2TMeta sources outputFile)
1208+ getT2TMeta sources outputFile
12131209 else case getReader readerName' of
12141210 Right r -> return r
12151211 Left e -> err 7 e'
@@ -1308,7 +1304,7 @@ main = do
13081304
13091305 let readFiles [] = error "Cannot read archive from stdin"
13101306 readFiles [x] = B.readFile x
1311− readFiles (x:xs) = mapM (warn . ("Ignoring: " ++)) xs >> B.readFile x
1307+ readFiles (x:xs) = mapM_ (warn . ("Ignoring: " ++)) xs >> B.readFile x
13121308
13131309 let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
13141310 then 0
@@ -1397,7 +1393,7 @@ main = do
13971393 else latexEngine
13981394 -- check for latex program
13991395 mbLatex <- findExecutable texprog
1400− when (mbLatex == Nothing) $
1396+ when (isNothing mbLatex) $
14011397 err 41 $ texprog ++ " not found. " ++
14021398 texprog ++ " is needed for pdf output."
14031399
@@ -1405,7 +1401,7 @@ main = do
14051401 case res of
14061402 Right pdf -> writeBinary pdf
14071403 Left err' -> do
1408− B.hPutStr stderr $ err'
1404+ B.hPutStr stderr err'
14091405 B.hPut stderr $ B.pack [10]
14101406 err 43 "Error producing PDF from TeX source"
14111407 | otherwise -> selfcontain (f writerOptions doc' ++