@@ -32,7 +32,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 Stability : alpha
32 Stability : alpha
33 Portability : portable
33 Portability : portable
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).
38module Text.Pandoc.Class ( PandocMonad(..)
42module Text.Pandoc.Class ( PandocMonad(..)
@@ -65,7 +69,6 @@ module Text.Pandoc.Class ( PandocMonad(..)
66 , runIOorExplode
70 , runIOorExplode
69 , fillMediaBag
72 , fillMediaBag
70 , extractMedia
73 , extractMedia
@@ -173,8 +176,9 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
173 modifyCommonState f = getCommonState >>= putCommonState . f
176 modifyCommonState f = getCommonState >>= putCommonState . f
174 -- Output a log message.
177 -- Output a log message.
175 logOutput :: LogMessage -> m ()
178 logOutput :: LogMessage -> m ()
176− -- Output a debug message to sterr, using 'Debug.Trace.trace'.
179+ -- Output a debug message to sterr, using 'Debug.Trace.trace',
177− -- Note: this writes to stderr even in pure instances.
180+ -- if tracing is enabled. Note: this writes to stderr even in
178 trace :: String -> m ()
182 trace :: String -> m ()
179 trace msg = do
183 trace msg = do
180 tracing <- getsCommonState stTrace
184 tracing <- getsCommonState stTrace
@@ -241,13 +245,26 @@ readFileFromDirs (d:ds) f = catchError
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.
244data CommonState = CommonState { stLog :: [LogMessage]
252data CommonState = CommonState { stLog :: [LogMessage]
253+ -- ^ A list of log messages in reverse order
245 , stMediaBag :: MediaBag
254 , stMediaBag :: MediaBag
255+ -- ^ Media parsed from binary containers
246 , stInputFiles :: Maybe [FilePath]
256 , stInputFiles :: Maybe [FilePath]
257+ -- ^ List of input files from command line
247 , stOutputFile :: Maybe FilePath
258 , stOutputFile :: Maybe FilePath
259+ -- ^ Output file from command line
248 , stResourcePath :: [FilePath]
260 , stResourcePath :: [FilePath]
261+ -- ^ Path to search for resources like
249 , stVerbosity :: Verbosity
263 , stVerbosity :: Verbosity
264+ -- ^ Verbosity level
250 , stTrace :: Bool
265 , stTrace :: Bool
266+ -- ^ Controls whether tracing messages are
253instance Default CommonState where
270instance Default CommonState where
@@ -260,12 +277,10 @@ instance Default CommonState where
260 , stTrace = False
277 , stTrace = False
280+-- | Evaluate a 'PandocIO' operation.
263runIO :: PandocIO a -> IO (Either PandocError a)
281runIO :: PandocIO a -> IO (Either PandocError a)
264runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
282runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
266−withMediaBag :: PandocMonad m => m a -> m (a, MediaBag)
267−withMediaBag ma = (,) <$> ma <*> getMediaBag
269runIOorExplode :: PandocIO a -> IO a
284runIOorExplode :: PandocIO a -> IO a
270runIOorExplode ma = runIO ma >>= handleError
285runIOorExplode ma = runIO ma >>= handleError