PandocMonad: add function runSilently [API Change]

The function runs an action in the PandocMonad, but returns all log
messages reported by that action instead of adding them to the main log.
This commit is contained in:
Albert Krewinkel
2025-07-31 11:15:12 +02:00
committed by John MacFarlane
parent 8799ad87b7
commit 57e7d895db
+18
View File
@@ -28,6 +28,7 @@ module Text.Pandoc.Class.PandocMonad
, getZonedTime
, readFileFromDirs
, report
, runSilently
, setRequestHeader
, setNoCheckCertificate
, getLog
@@ -192,6 +193,23 @@ report msg = do
when (level <= verbosity) $ logOutput msg
modifyCommonState $ \st -> st{ stLog = msg : stLog st }
-- | Run an action, but suppress the output of any log messages;
-- instead, all messages reported by @action@ are returned separately
-- and not added to the main log.
runSilently :: PandocMonad m => m a -> m (a, [LogMessage])
runSilently action = do
-- get current settings
origLog <- getsCommonState stLog
origVerbosity <- getVerbosity
-- reset log level and set verbosity to the minimum
modifyCommonState (\st -> st { stVerbosity = ERROR, stLog = []})
result <- action
-- get log messages reported while running `action`
newLog <- getsCommonState stLog
modifyCommonState (\st -> st { stVerbosity = origVerbosity, stLog = origLog})
return (result, newLog)
-- | Set request header to use in HTTP requests.
setRequestHeader :: PandocMonad m
=> T.Text -- ^ Header name