summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2016-12-01 10:00:21 -0500
committerJohn MacFarlane <jgm@berkeley.edu>2017-01-25 17:07:40 +0100
commit52859b98632e991e94a3d37c0e0ae6c5d3b3fa34 (patch)
tree28ff8b504731426879c016c4e1087a7ee042383c /src
parent5a02a81b43f1081aa6fb7025428f416cfd4abaa4 (diff)
Finish converting readers over.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Class.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index 0abd0361e..12566a51c 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -44,6 +44,7 @@ module Text.Pandoc.Class ( PandocMonad(..)
, runIO
, runIOorExplode
, runPure
+ , withMediaBag
) where
import Prelude hiding (readFile, fail)
@@ -115,6 +116,7 @@ class (Functor m, Applicative m, Monad m, MonadError PandocExecutionError m) =>
-- to the record names, so I'd like to work out a better way to deal
-- with it.
setMediaBag :: MediaBag -> m ()
+ getMediaBag :: m MediaBag
insertMedia :: FilePath -> Maybe MimeType -> BL.ByteString -> m ()
getInputFiles :: m (Maybe [FilePath])
getOutputFile :: m (Maybe FilePath)
@@ -169,6 +171,9 @@ instance Default PandocEnvIO where
runIO :: PandocIO a -> IO (Either PandocExecutionError a)
runIO ma = flip evalStateT def $ flip runReaderT def $ runExceptT $ unPandocIO ma
+withMediaBag :: PandocMonad m => m a -> m (a, MediaBag)
+withMediaBag ma = ((,)) <$> ma <*> getMediaBag
+
runIOorExplode :: PandocIO a -> IO a
runIOorExplode ma = do
eitherVal <- runIO ma
@@ -179,6 +184,10 @@ runIOorExplode ma = do
Left (PandocParseError s) -> error $ "parse error" ++ s
Left (PandocSomeError s) -> error s
+
+
+
+
newtype PandocIO a = PandocIO {
unPandocIO :: ExceptT PandocExecutionError (ReaderT PandocEnvIO (StateT PandocStateIO IO)) a
} deriving ( MonadIO
@@ -225,6 +234,7 @@ instance PandocMonad PandocIO where
-- Common functions
setMediaBag mb =
modify $ \st -> st{ioStMediaBag = mb}
+ getMediaBag = gets ioStMediaBag
insertMedia fp mime bs =
modify $ \st -> st{ioStMediaBag = MB.insertMedia fp mime bs (ioStMediaBag st) }
getInputFiles = asks ioEnvInputFiles
@@ -383,6 +393,8 @@ instance PandocMonad PandocPure where
setMediaBag mb =
modify $ \st -> st{stMediaBag = mb}
+ getMediaBag = gets stMediaBag
+
insertMedia fp mime bs =
modify $ \st -> st{stMediaBag = MB.insertMedia fp mime bs (stMediaBag st) }