{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Text.Pandoc.Class.PandocIO
( PandocIO(..)
, runIO
, runIOorExplode
, extractMedia
) where
import Control.Monad.Except (ExceptT, MonadError, runExceptT)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.State (StateT, evalStateT, lift, get, put)
import Data.Default (Default (def))
import Text.Pandoc.Class.CommonState (CommonState (..))
import Text.Pandoc.Class.PandocMonad
import Text.Pandoc.Definition
import Text.Pandoc.Error
import qualified Text.Pandoc.Class.IO as IO
import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow)
runIO :: PandocIO a -> IO (Either PandocError a)
runIO :: forall a. PandocIO a -> IO (Either PandocError a)
runIO PandocIO a
ma = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT forall a. Default a => a
def forall a b. (a -> b) -> a -> b
$ forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT forall a b. (a -> b) -> a -> b
$ forall a.
PandocIO a -> ExceptT PandocError (StateT CommonState IO) a
unPandocIO PandocIO a
ma
runIOorExplode :: PandocIO a -> IO a
runIOorExplode :: forall a. PandocIO a -> IO a
runIOorExplode PandocIO a
ma = forall a. PandocIO a -> IO (Either PandocError a)
runIO PandocIO a
ma forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. Either PandocError a -> IO a
handleError
newtype PandocIO a = PandocIO {
forall a.
PandocIO a -> ExceptT PandocError (StateT CommonState IO) a
unPandocIO :: ExceptT PandocError (StateT CommonState IO) a
} deriving ( Monad PandocIO
forall a. IO a -> PandocIO a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: forall a. IO a -> PandocIO a
$cliftIO :: forall a. IO a -> PandocIO a
MonadIO
, forall a b. a -> PandocIO b -> PandocIO a
forall a b. (a -> b) -> PandocIO a -> PandocIO b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PandocIO b -> PandocIO a
$c<$ :: forall a b. a -> PandocIO b -> PandocIO a
fmap :: forall a b. (a -> b) -> PandocIO a -> PandocIO b
$cfmap :: forall a b. (a -> b) -> PandocIO a -> PandocIO b
Functor
, Functor PandocIO
forall a. a -> PandocIO a
forall a b. PandocIO a -> PandocIO b -> PandocIO a
forall a b. PandocIO a -> PandocIO b -> PandocIO b
forall a b. PandocIO (a -> b) -> PandocIO a -> PandocIO b
forall a b c.
(a -> b -> c) -> PandocIO a -> PandocIO b -> PandocIO c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b. PandocIO a -> PandocIO b -> PandocIO a
$c<* :: forall a b. PandocIO a -> PandocIO b -> PandocIO a
*> :: forall a b. PandocIO a -> PandocIO b -> PandocIO b
$c*> :: forall a b. PandocIO a -> PandocIO b -> PandocIO b
liftA2 :: forall a b c.
(a -> b -> c) -> PandocIO a -> PandocIO b -> PandocIO c
$cliftA2 :: forall a b c.
(a -> b -> c) -> PandocIO a -> PandocIO b -> PandocIO c
<*> :: forall a b. PandocIO (a -> b) -> PandocIO a -> PandocIO b
$c<*> :: forall a b. PandocIO (a -> b) -> PandocIO a -> PandocIO b
pure :: forall a. a -> PandocIO a
$cpure :: forall a. a -> PandocIO a
Applicative
, Applicative PandocIO
forall a. a -> PandocIO a
forall a b. PandocIO a -> PandocIO b -> PandocIO b
forall a b. PandocIO a -> (a -> PandocIO b) -> PandocIO b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> PandocIO a
$creturn :: forall a. a -> PandocIO a
>> :: forall a b. PandocIO a -> PandocIO b -> PandocIO b
$c>> :: forall a b. PandocIO a -> PandocIO b -> PandocIO b
>>= :: forall a b. PandocIO a -> (a -> PandocIO b) -> PandocIO b
$c>>= :: forall a b. PandocIO a -> (a -> PandocIO b) -> PandocIO b
Monad
, MonadThrow PandocIO
forall e a.
Exception e =>
PandocIO a -> (e -> PandocIO a) -> PandocIO a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
catch :: forall e a.
Exception e =>
PandocIO a -> (e -> PandocIO a) -> PandocIO a
$ccatch :: forall e a.
Exception e =>
PandocIO a -> (e -> PandocIO a) -> PandocIO a
MonadCatch
, MonadCatch PandocIO
forall b.
((forall a. PandocIO a -> PandocIO a) -> PandocIO b) -> PandocIO b
forall a b c.
PandocIO a
-> (a -> ExitCase b -> PandocIO c)
-> (a -> PandocIO b)
-> PandocIO (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
generalBracket :: forall a b c.
PandocIO a
-> (a -> ExitCase b -> PandocIO c)
-> (a -> PandocIO b)
-> PandocIO (b, c)
$cgeneralBracket :: forall a b c.
PandocIO a
-> (a -> ExitCase b -> PandocIO c)
-> (a -> PandocIO b)
-> PandocIO (b, c)
uninterruptibleMask :: forall b.
((forall a. PandocIO a -> PandocIO a) -> PandocIO b) -> PandocIO b
$cuninterruptibleMask :: forall b.
((forall a. PandocIO a -> PandocIO a) -> PandocIO b) -> PandocIO b
mask :: forall b.
((forall a. PandocIO a -> PandocIO a) -> PandocIO b) -> PandocIO b
$cmask :: forall b.
((forall a. PandocIO a -> PandocIO a) -> PandocIO b) -> PandocIO b
MonadMask
, Monad PandocIO
forall e a. Exception e => e -> PandocIO a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
throwM :: forall e a. Exception e => e -> PandocIO a
$cthrowM :: forall e a. Exception e => e -> PandocIO a
MonadThrow
, MonadError PandocError
)
instance PandocMonad PandocIO where
lookupEnv :: Text -> PandocIO (Maybe Text)
lookupEnv = forall (m :: * -> *). MonadIO m => Text -> m (Maybe Text)
IO.lookupEnv
getCurrentTime :: PandocIO UTCTime
getCurrentTime = forall (m :: * -> *). MonadIO m => m UTCTime
IO.getCurrentTime
getCurrentTimeZone :: PandocIO TimeZone
getCurrentTimeZone = forall (m :: * -> *). MonadIO m => m TimeZone
IO.getCurrentTimeZone
newStdGen :: PandocIO StdGen
newStdGen = forall (m :: * -> *). MonadIO m => m StdGen
IO.newStdGen
newUniqueHash :: PandocIO Int
newUniqueHash = forall (m :: * -> *). MonadIO m => m Int
IO.newUniqueHash
openURL :: Text -> PandocIO (ByteString, Maybe Text)
openURL = forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Text -> m (ByteString, Maybe Text)
IO.openURL
readFileLazy :: FilePath -> PandocIO ByteString
readFileLazy = forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
FilePath -> m ByteString
IO.readFileLazy
readFileStrict :: FilePath -> PandocIO ByteString
readFileStrict = forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
FilePath -> m ByteString
IO.readFileStrict
readStdinStrict :: PandocIO ByteString
readStdinStrict = forall (m :: * -> *). (PandocMonad m, MonadIO m) => m ByteString
IO.readStdinStrict
glob :: FilePath -> PandocIO [FilePath]
glob = forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
FilePath -> m [FilePath]
IO.glob
fileExists :: FilePath -> PandocIO Bool
fileExists = forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
FilePath -> m Bool
IO.fileExists
getDataFileName :: FilePath -> PandocIO FilePath
getDataFileName = forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
FilePath -> m FilePath
IO.getDataFileName
getModificationTime :: FilePath -> PandocIO UTCTime
getModificationTime = forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
FilePath -> m UTCTime
IO.getModificationTime
getCommonState :: PandocIO CommonState
getCommonState = forall a.
ExceptT PandocError (StateT CommonState IO) a -> PandocIO a
PandocIO forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall s (m :: * -> *). MonadState s m => m s
get
putCommonState :: CommonState -> PandocIO ()
putCommonState = forall a.
ExceptT PandocError (StateT CommonState IO) a -> PandocIO a
PandocIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *). MonadState s m => s -> m ()
put
logOutput :: LogMessage -> PandocIO ()
logOutput = forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
LogMessage -> m ()
IO.logOutput
extractMedia :: (PandocMonad m, MonadIO m) => FilePath -> Pandoc -> m Pandoc
= forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
FilePath -> Pandoc -> m Pandoc
IO.extractMedia