aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-07-30 12:23:58 -0700
committerJohn MacFarlane <[email protected]>2025-08-01 10:04:14 -0700
commit8799ad87b797e67577bc5368580685c3fa8e97fb (patch)
treed19804af7857769f3a73c8ad76eab5c91d66a418
parentc77476b597ef89e9ab7baf3452f84cd4f5ff1a5a (diff)
Make CommonState opaque.
Text.Pandoc.Class now exports CommonState as an opaque object, without its fields. [API change] The internal module Text.Pandoc.Class.CommonState still exports the fields. Text.Pandoc.Class now exports the following new functions: `getRequestHeaders`, `setRequestHeaders`, `getSourceURL`, `getTrace`. [API change]
-rw-r--r--src/Text/Pandoc/Class.hs4
-rw-r--r--src/Text/Pandoc/Class/PandocMonad.hs33
-rw-r--r--src/Text/Pandoc/Translations.hs3
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(..))