git.iko.soy/typeable/pandoc
on master help sign in
Some hlint refactoring.
commit0cf6511f16388fc2bb71cffc733a704d20cfe3e3 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 1 Jun 2017, 15:09 (9 years ago) parentc00471c
3 files changed+34−38
pandoc.hs+3−3 src/Text/Pandoc/App.hs+18−19 src/Text/Pandoc/Class.hs+13−16
pandoc.hs+3−3
@@ -1,5 +1,5 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE PatternGuards #-}
2+
33{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE TupleSections #-}
55{-
@@ -33,9 +33,9 @@ Parses command-line options and calls the appropriate readers and
3333writers.
3434-}
3535module Main where
36−import Text.Pandoc.App (convertWithOpts, defaultOpts, options, parseOptions)
37−import Text.Pandoc.Error (handleError, PandocError)
3836import qualified Control.Exception as E
37+import Text.Pandoc.App (convertWithOpts, defaultOpts, options, parseOptions)
38+import Text.Pandoc.Error (PandocError, handleError)
3939
4040main :: IO ()
4141main = E.catch (parseOptions options defaultOpts >>= convertWithOpts)
src/Text/Pandoc/App.hs+18−19
@@ -1,7 +1,7 @@
11{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveGeneric #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34{-# LANGUAGE TupleSections #-}
4−{-# LANGUAGE DeriveGeneric #-}
55{-
66Copyright (C) 2006-2017 John MacFarlane <jgm@berkeley.edu>
77
@@ -40,47 +40,47 @@ module Text.Pandoc.App (
4040 ) where
4141import Control.Applicative ((<|>))
4242import qualified Control.Exception as E
43−import Control.Monad.Except (throwError)
4443import Control.Monad
44+import Control.Monad.Except (throwError)
4545import Control.Monad.Trans
46−import Data.Aeson (eitherDecode', encode, ToJSON(..), FromJSON(..),
47− genericToEncoding, defaultOptions)
46+import Data.Aeson (FromJSON (..), ToJSON (..), defaultOptions, eitherDecode',
47+ encode, genericToEncoding)
4848import qualified Data.ByteString as BS
4949import qualified Data.ByteString.Lazy as B
5050import Data.Char (toLower, toUpper)
51−import qualified Data.Set as Set
5251import Data.Foldable (foldrM)
53−import GHC.Generics
5452import Data.List (intercalate, isPrefixOf, isSuffixOf, sort)
5553import qualified Data.Map as M
5654import Data.Maybe (fromMaybe, isJust, isNothing)
55+import qualified Data.Set as Set
5756import qualified Data.Text as T
5857import Data.Yaml (decode)
5958import qualified Data.Yaml as Yaml
59+import GHC.Generics
6060import Network.URI (URI (..), parseURI)
6161import Paths_pandoc (getDataDir)
6262import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme)
63−import Skylighting.Parser (missingIncludes, parseSyntaxDefinition,
64− addSyntaxDefinition)
63+import Skylighting.Parser (addSyntaxDefinition, missingIncludes,
64+ parseSyntaxDefinition)
6565import System.Console.GetOpt
6666import System.Directory (Permissions (..), doesFileExist, findExecutable,
6767 getAppUserDataDirectory, getPermissions)
6868import System.Environment (getArgs, getEnvironment, getProgName)
6969import System.Exit (ExitCode (..), exitSuccess)
7070import System.FilePath
71−import System.IO (stdout, nativeNewline)
72−import qualified System.IO as IO (Newline(..))
71+import System.IO (nativeNewline, stdout)
72+import qualified System.IO as IO (Newline (..))
7373import System.IO.Error (isDoesNotExistError)
7474import Text.Pandoc
7575import Text.Pandoc.Builder (setMeta)
76−import Text.Pandoc.Class (PandocIO, getLog, withMediaBag,
77− extractMedia, fillMediaBag, setResourcePath)
76+import Text.Pandoc.Class (PandocIO, extractMedia, fillMediaBag, getLog,
77+ setResourcePath, withMediaBag)
7878import Text.Pandoc.Highlighting (highlightingStyles)
79−import Text.Pandoc.Lua ( runLuaFilter )
79+import Text.Pandoc.Lua (runLuaFilter)
8080import Text.Pandoc.PDF (makePDF)
8181import Text.Pandoc.Process (pipeProcess)
82−import Text.Pandoc.SelfContained (makeSelfContained, makeDataURI)
83−import Text.Pandoc.Shared (isURI, headerShift, openURL, readDataFile,
82+import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
83+import Text.Pandoc.Shared (headerShift, isURI, openURL, readDataFile,
8484 readDataFileUTF8, safeRead, tabFilter)
8585import qualified Text.Pandoc.UTF8 as UTF8
8686import Text.Pandoc.XML (toEntities)
@@ -243,10 +243,9 @@ convertWithOpts opts = do
243243 withList f (x:xs) vars = f x vars >>= withList f xs
244244
245245 variables <-
246− return (("outputfile", optOutputFile opts) : optVariables opts)
247− >>=
246+
248247 withList (addStringAsVariable "sourcefile")
249− (reverse $ optInputFiles opts)
248+ (reverse $ optInputFiles opts) (("outputfile", optOutputFile opts) : optVariables opts)
250249 -- we reverse this list because, unlike
251250 -- the other option lists here, it is
252251 -- not reversed when parsed from CLI arguments.
@@ -796,7 +795,7 @@ readURI :: FilePath -> PandocIO String
796795readURI src = do
797796 res <- liftIO $ openURL src
798797 case res of
799− Left e -> throwError $ PandocHttpError src e
798+ Left e -> throwError $ PandocHttpError src e
800799 Right (contents, _) -> return $ UTF8.toString contents
801800
802801readFile' :: MonadIO m => FilePath -> m B.ByteString
src/Text/Pandoc/Class.hs+13−16
@@ -1,10 +1,8 @@
11{-# LANGUAGE DeriveFunctor #-}
2−{-# LANGUAGE DeriveDataTypeable #-}
32{-# LANGUAGE TypeSynonymInstances #-}
43{-# LANGUAGE FlexibleInstances #-}
54{-# LANGUAGE GeneralizedNewtypeDeriving #-}
65{-# LANGUAGE FlexibleContexts #-}
7−{-# LANGUAGE StandaloneDeriving #-}
86
97{-
108Copyright (C) 2016 Jesse Rosenthal <jrosenthal@jhu.edu>
@@ -156,7 +154,7 @@ report :: PandocMonad m => LogMessage -> m ()
156154report msg = do
157155 verbosity <- getsCommonState stVerbosity
158156 let level = messageVerbosity msg
159− when (level <= verbosity) $ do
157+ when (level <= verbosity) $
160158 logOutput msg
161159 unless (level == DEBUG) $
162160 modifyCommonState $ \st -> st{ stLog = msg : stLog st }
@@ -224,7 +222,7 @@ runIO :: PandocIO a -> IO (Either PandocError a)
224222runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
225223
226224withMediaBag :: PandocMonad m => m a -> m (a, MediaBag)
227−withMediaBag ma = ((,)) <$> ma <*> getMediaBag
225+withMediaBag ma = (,) <$> ma <*> getMediaBag
228226
229227runIOorExplode :: PandocIO a -> IO a
230228runIOorExplode ma = runIO ma >>= handleError
@@ -250,7 +248,7 @@ instance PandocMonad PandocIO where
250248 getCurrentTime = liftIO IO.getCurrentTime
251249 getCurrentTimeZone = liftIO IO.getCurrentTimeZone
252250 newStdGen = liftIO IO.newStdGen
253− newUniqueHash = hashUnique <$> (liftIO IO.newUnique)
251+ newUniqueHash = hashUnique <$> liftIO IO.newUnique
254252 openURL u = do
255253 report $ Fetching u
256254 res <- liftIO (IO.openURL u)
@@ -266,7 +264,7 @@ instance PandocMonad PandocIO where
266264 putCommonState x = PandocIO $ lift $ put x
267265 logOutput msg = liftIO $ do
268266 UTF8.hPutStr stderr $ "[" ++
269− (map toLower $ show (messageVerbosity msg)) ++ "] "
267+ map toLower (show (messageVerbosity msg)) ++ "] "
270268 alertIndent $ lines $ showLogMessage msg
271269
272270alertIndent :: [String] -> IO ()
@@ -297,14 +295,14 @@ fetchItem :: PandocMonad m
297295fetchItem sourceURL s = do
298296 mediabag <- getMediaBag
299297 case lookupMedia s mediabag of
300− Just (mime, bs) -> return $ (BL.toStrict bs, Just mime)
298+ Just (mime, bs) -> return (BL.toStrict bs, Just mime)
301299 Nothing -> downloadOrRead sourceURL s
302300
303301downloadOrRead :: PandocMonad m
304302 => Maybe String
305303 -> String
306304 -> m (B.ByteString, Maybe MimeType)
307−downloadOrRead sourceURL s = do
305+downloadOrRead sourceURL s =
308306 case (sourceURL >>= parseURIReference' .
309307 ensureEscaped, ensureEscaped s) of
310308 (Just u, s') -> -- try fetching from relative path at source
@@ -367,7 +365,7 @@ fillMediaBag sourceURL d = walkM handleImage d
367365 let fname = basename <.> ext
368366 insertMedia fname mt bs'
369367 return $ Image attr lab (fname, tit))
370− (\e -> do
368+ (\e ->
371369 case e of
372370 PandocResourceNotFound _ -> do
373371 report $ CouldNotFetchResource src
@@ -434,7 +432,7 @@ instance Default PureState where
434432
435433
436434getPureState :: PandocPure PureState
437−getPureState = PandocPure $ lift $ lift $ get
435+getPureState = PandocPure $ lift $ lift get
438436
439437getsPureState :: (PureState -> a) -> PandocPure a
440438getsPureState f = f <$> getPureState
@@ -505,16 +503,16 @@ instance PandocMonad PandocPure where
505503 case infoFileContents <$> getFileInfo fp fps of
506504 Just bs -> return bs
507505 Nothing -> throwError $ PandocResourceNotFound fp
508− readDataFile Nothing "reference.docx" = do
506+ readDataFile Nothing "reference.docx" =
509507 (B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceDocx
510− readDataFile Nothing "reference.odt" = do
508+ readDataFile Nothing "reference.odt" =
511509 (B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceODT
512510 readDataFile Nothing fname = do
513511 let fname' = if fname == "MANUAL.txt" then fname else "data" </> fname
514512 readFileStrict fname'
515513 readDataFile (Just userDir) fname = do
516514 userDirFiles <- getsPureState stUserDataDir
517− case infoFileContents <$> (getFileInfo (userDir </> fname) userDirFiles) of
515+ case infoFileContents <$> getFileInfo (userDir </> fname) userDirFiles of
518516 Just bs -> return bs
519517 Nothing -> readDataFile Nothing fname
520518
@@ -524,12 +522,12 @@ instance PandocMonad PandocPure where
524522
525523 getModificationTime fp = do
526524 fps <- getsPureState stFiles
527− case infoFileMTime <$> (getFileInfo fp fps) of
525+ case infoFileMTime <$> getFileInfo fp fps of
528526 Just tm -> return tm
529527 Nothing -> throwError $ PandocIOError fp
530528 (userError "Can't get modification time")
531529
532− getCommonState = PandocPure $ lift $ get
530+ getCommonState = PandocPure $ lift get
533531 putCommonState x = PandocPure $ lift $ put x
534532
535533 logOutput _msg = return ()
@@ -613,4 +611,3 @@ instance PandocMonad m => PandocMonad (StateT st m) where
613611 getCommonState = lift getCommonState
614612 putCommonState = lift . putCommonState
615613 logOutput = lift . logOutput
616−