@@ -32,7 +32,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3232 Stability : alpha
3333 Portability : portable
3434
35−Typeclass for pandoc readers and writers, allowing both IO and pure instances.
35+This module defines a type class, 'PandocMonad', for pandoc readers
36+and writers. A pure instance 'PandocPure' and an impure instance
37+'PandocIO' are provided. This allows users of the library to choose
38+whether they want conversions to perform IO operations (such as
39+reading include files or images).
3640-}
3741
3842module Text.Pandoc.Class ( PandocMonad(..)
@@ -65,7 +69,6 @@ module Text.Pandoc.Class ( PandocMonad(..)
6569 , runIO
6670 , runIOorExplode
6771 , runPure
68− , withMediaBag
6972 , fillMediaBag
7073 , extractMedia
7174 ) where
@@ -173,8 +176,9 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
173176 modifyCommonState f = getCommonState >>= putCommonState . f
174177 -- Output a log message.
175178 logOutput :: LogMessage -> m ()
176− -- Output a debug message to sterr, using 'Debug.Trace.trace'.
177− -- Note: this writes to stderr even in pure instances.
179+ -- Output a debug message to sterr, using 'Debug.Trace.trace',
180+ -- if tracing is enabled. Note: this writes to stderr even in
181+ -- pure instances.
178182 trace :: String -> m ()
179183 trace msg = do
180184 tracing <- getsCommonState stTrace
@@ -241,13 +245,26 @@ readFileFromDirs (d:ds) f = catchError
241245
242246--
243247
248+-- | 'CommonState' represents state that is used by all
249+-- instances of 'PandocMonad'. Normally users should not
250+-- need to interact with it directly; instead, auxiliary
251+-- functions like 'setVerbosity' and 'withMediaBag' should be used.
244252data CommonState = CommonState { stLog :: [LogMessage]
253+ -- ^ A list of log messages in reverse order
245254 , stMediaBag :: MediaBag
255+ -- ^ Media parsed from binary containers
246256 , stInputFiles :: Maybe [FilePath]
257+ -- ^ List of input files from command line
247258 , stOutputFile :: Maybe FilePath
259+ -- ^ Output file from command line
248260 , stResourcePath :: [FilePath]
261+ -- ^ Path to search for resources like
262+ -- included images
249263 , stVerbosity :: Verbosity
264+ -- ^ Verbosity level
250265 , stTrace :: Bool
266+ -- ^ Controls whether tracing messages are
267+ -- issued.
251268 }
252269
253270instance Default CommonState where
@@ -260,12 +277,10 @@ instance Default CommonState where
260277 , stTrace = False
261278 }
262279
280+-- | Evaluate a 'PandocIO' operation.
263281runIO :: PandocIO a -> IO (Either PandocError a)
264282runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
265283
266−withMediaBag :: PandocMonad m => m a -> m (a, MediaBag)
267−withMediaBag ma = (,) <$> ma <*> getMediaBag
268−
269284runIOorExplode :: PandocIO a -> IO a
270285runIOorExplode ma = runIO ma >>= handleError
271286