@@ -110,9 +110,15 @@ class (Functor m, Applicative m, Monad m, MonadError PandocExecutionError m) =>
110110 getWarnings :: m [String]
111111 fail :: String -> m b
112112 glob :: String -> m [FilePath]
113+ getModificationTime :: FilePath -> m UTCTime
114+ -- The following are common to all instantiations of the monad, up
115+ -- to the record names, so I'd like to work out a better way to deal
116+ -- with it.
113117 setMediaBag :: MediaBag -> m ()
114118 insertMedia :: FilePath -> Maybe MimeType -> BL.ByteString -> m ()
115− getModificationTime :: FilePath -> m UTCTime
119+ getInputFiles :: m (Maybe [FilePath])
120+ getOutputFile :: m (Maybe FilePath)
121+
116122
117123
118124--Some functions derived from Primitives:
@@ -152,8 +158,16 @@ instance Default PandocStateIO where
152158 , ioStMediaBag = mempty
153159 }
154160
161+data PandocEnvIO = PandocEnvIO { ioEnvInputFiles :: Maybe [FilePath]
162+ , ioEnvOutputFile :: Maybe FilePath
163+ }
164+instance Default PandocEnvIO where
165+ def = PandocEnvIO { ioEnvInputFiles = Nothing -- stdin
166+ , ioEnvOutputFile = Nothing -- stdout
167+ }
168+
155169runIO :: PandocIO a -> IO (Either PandocExecutionError a)
156−runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
170+runIO ma = flip evalStateT def $ flip runReaderT def $ runExceptT $ unPandocIO ma
157171
158172runIOorExplode :: PandocIO a -> IO a
159173runIOorExplode ma = do
@@ -166,11 +180,12 @@ runIOorExplode ma = do
166180 Left (PandocSomeError s) -> error s
167181
168182newtype PandocIO a = PandocIO {
169− unPandocIO :: ExceptT PandocExecutionError (StateT PandocStateIO IO) a
183+ unPandocIO :: ExceptT PandocExecutionError (ReaderT PandocEnvIO (StateT PandocStateIO IO)) a
170184 } deriving ( MonadIO
171185 , Functor
172186 , Applicative
173187 , Monad
188+ , MonadReader PandocEnvIO
174189 , MonadState PandocStateIO
175190 , MonadError PandocExecutionError
176191 )
@@ -202,15 +217,20 @@ instance PandocMonad PandocIO where
202217 liftIO $ IO.warn msg
203218 getWarnings = gets ioStWarnings
204219 glob = liftIO . IO.glob
205− setMediaBag mb =
206− modify $ \st -> st{ioStMediaBag = mb}
207− insertMedia fp mime bs =
208− modify $ \st -> st{ioStMediaBag = MB.insertMedia fp mime bs (ioStMediaBag st) }
209220 getModificationTime fp = do
210221 eitherMtime <- liftIO (tryIOError $ IO.getModificationTime fp)
211222 case eitherMtime of
212223 Right mtime -> return mtime
213224 Left _ -> throwError $ PandocFileReadError fp
225+ -- Common functions
226+ setMediaBag mb =
227+ modify $ \st -> st{ioStMediaBag = mb}
228+ insertMedia fp mime bs =
229+ modify $ \st -> st{ioStMediaBag = MB.insertMedia fp mime bs (ioStMediaBag st) }
230+ getInputFiles = asks ioEnvInputFiles
231+ getOutputFile = asks ioEnvOutputFile
232+
233+
214234
215235data PureState = PureState { stStdGen :: StdGen
216236 , stWord8Store :: [Word8] -- should be
@@ -253,6 +273,8 @@ data PureEnv = PureEnv { envEnv :: [(String, String)]
253273 , envUserDataDir :: FileTree
254274 , envCabalDataDir :: FileTree
255275 , envFontFiles :: [FilePath]
276+ , envInputFiles :: Maybe [FilePath]
277+ , envOutputFile :: Maybe FilePath
256278 }
257279
258280-- We have to figure this out a bit more. But let's put some empty
@@ -267,6 +289,8 @@ instance Default PureEnv where
267289 , envUserDataDir = mempty
268290 , envCabalDataDir = mempty
269291 , envFontFiles = []
292+ , envInputFiles = Nothing
293+ , envOutputFile = Nothing
270294 }
271295
272296instance E.Exception PandocExecutionError
@@ -348,14 +372,26 @@ instance PandocMonad PandocPure where
348372 fontFiles <- asks envFontFiles
349373 return (filter (match (compile s)) fontFiles)
350374
375+ getModificationTime fp = do
376+ fps <- asks envFiles
377+ case infoFileMTime <$> (getFileInfo fp fps) of
378+ Just tm -> return tm
379+ Nothing -> throwError $ PandocFileReadError fp
380+
381+ -- Common files
382+
351383 setMediaBag mb =
352384 modify $ \st -> st{stMediaBag = mb}
353385
354386 insertMedia fp mime bs =
355387 modify $ \st -> st{stMediaBag = MB.insertMedia fp mime bs (stMediaBag st) }
356388
357− getModificationTime fp = do
358− fps <- asks envFiles
359− case infoFileMTime <$> (getFileInfo fp fps) of
360− Just tm -> return tm
361− Nothing -> throwError $ PandocFileReadError fp
389+ getInputFiles = asks envInputFiles
390+
391+ getOutputFile = asks envOutputFile
392+
393+
394+
395+
396+
397+