diff options
| -rw-r--r-- | src/Text/Pandoc/Class.hs | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Class/PandocMonad.hs | 33 | ||||
| -rw-r--r-- | src/Text/Pandoc/Translations.hs | 3 |
3 files changed, 31 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs index a1e51e0cf..7df67236b 100644 --- a/src/Text/Pandoc/Class.hs +++ b/src/Text/Pandoc/Class.hs @@ -23,7 +23,9 @@ module Text.Pandoc.Class , Translations ) where -import Text.Pandoc.Class.CommonState (CommonState (..)) +-- We export CommonState as an opaque object. Accessors for +-- its fields are provided in Text.Pandoc.Class.PandocMonad. +import Text.Pandoc.Class.CommonState (CommonState) import Text.Pandoc.Class.PandocMonad import Text.Pandoc.Class.PandocIO import Text.Pandoc.Class.PandocPure diff --git a/src/Text/Pandoc/Class/PandocMonad.hs b/src/Text/Pandoc/Class/PandocMonad.hs index 850aff584..7fc89bdab 100644 --- a/src/Text/Pandoc/Class/PandocMonad.hs +++ b/src/Text/Pandoc/Class/PandocMonad.hs @@ -28,12 +28,13 @@ module Text.Pandoc.Class.PandocMonad , getZonedTime , readFileFromDirs , report - , setTrace , setRequestHeader , setNoCheckCertificate , getLog , setVerbosity , getVerbosity + , setTrace + , getTrace , getMediaBag , setMediaBag , insertMedia @@ -47,6 +48,9 @@ module Text.Pandoc.Class.PandocMonad , setOutputFile , setResourcePath , getResourcePath + , setRequestHeaders + , getRequestHeaders + , getSourceURL , readMetadataFile , toTextM , fillMediaBag @@ -164,6 +168,15 @@ setVerbosity verbosity = getVerbosity :: PandocMonad m => m Verbosity getVerbosity = getsCommonState stVerbosity +-- | Set tracing. This affects the behavior of 'trace'. If tracing +-- is not enabled, 'trace' does nothing. +setTrace :: PandocMonad m => Bool -> m () +setTrace enabled = modifyCommonState $ \st -> st{ stTrace = enabled } + +-- | Get tracing status. +getTrace :: PandocMonad m => m Bool +getTrace = getsCommonState stTrace + -- | Get the accumulated log messages (in temporal order). getLog :: PandocMonad m => m [LogMessage] getLog = reverse <$> getsCommonState stLog @@ -179,12 +192,6 @@ report msg = do when (level <= verbosity) $ logOutput msg modifyCommonState $ \st -> st{ stLog = msg : stLog st } --- | Determine whether tracing is enabled. This affects --- the behavior of 'trace'. If tracing is not enabled, --- 'trace' does nothing. -setTrace :: PandocMonad m => Bool -> m () -setTrace useTracing = modifyCommonState $ \st -> st{stTrace = useTracing} - -- | Set request header to use in HTTP requests. setRequestHeader :: PandocMonad m => T.Text -- ^ Header name @@ -248,6 +255,18 @@ getResourcePath = getsCommonState stResourcePath setResourcePath :: PandocMonad m => [FilePath] -> m () setResourcePath ps = modifyCommonState $ \st -> st{stResourcePath = ps} +-- | Retrieve the request headers to add for HTTP requests. +getRequestHeaders :: PandocMonad m => m [(T.Text, T.Text)] +getRequestHeaders = getsCommonState stRequestHeaders + +-- | Set the request headers to add for HTTP requests. +setRequestHeaders :: PandocMonad m => [(T.Text, T.Text)] -> m () +setRequestHeaders hs = modifyCommonState $ \st -> st{ stRequestHeaders = hs } + +-- | Get the absolute UL or directory of first source file. +getSourceURL :: PandocMonad m => m (Maybe T.Text) +getSourceURL = getsCommonState stSourceURL + -- | Get the current UTC time. If the @SOURCE_DATE_EPOCH@ environment -- variable is set to a unix time (number of seconds since midnight -- Jan 01 1970 UTC), it is used instead of the current time, to support diff --git a/src/Text/Pandoc/Translations.hs b/src/Text/Pandoc/Translations.hs index 3be76335e..00562e189 100644 --- a/src/Text/Pandoc/Translations.hs +++ b/src/Text/Pandoc/Translations.hs @@ -20,7 +20,8 @@ module Text.Pandoc.Translations ( ) where import Text.Pandoc.Translations.Types -import Text.Pandoc.Class (PandocMonad(..), CommonState(..), toTextM, report) +import Text.Pandoc.Class (PandocMonad(..), toTextM, report) +import Text.Pandoc.Class.CommonState (CommonState(..)) import Text.Pandoc.Data (readDataFile) import Text.Pandoc.Error (PandocError(..)) import Text.Pandoc.Logging (LogMessage(..)) |
