aboutsummaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/src/Text/Pandoc/Lua/Module
diff options
context:
space:
mode:
Diffstat (limited to 'pandoc-lua-engine/src/Text/Pandoc/Lua/Module')
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs24
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs10
2 files changed, 9 insertions, 25 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs
index 135591981..b885cae74 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Log.hs
@@ -14,14 +14,9 @@ module Text.Pandoc.Lua.Module.Log
import Data.Version (makeVersion)
import HsLua
-import Text.Pandoc.Class
- ( CommonState (stVerbosity, stLog)
- , PandocMonad (putCommonState, getCommonState)
- , report )
+import Text.Pandoc.Class (report, runSilently)
import Text.Pandoc.Error (PandocError)
-import Text.Pandoc.Logging
- ( Verbosity (ERROR)
- , LogMessage (ScriptingInfo, ScriptingWarning) )
+import Text.Pandoc.Logging (LogMessage (ScriptingInfo, ScriptingWarning))
import Text.Pandoc.Lua.Marshal.List (pushPandocList)
import Text.Pandoc.Lua.Marshal.LogMessage (pushLogMessage)
import Text.Pandoc.Lua.PandocLua (liftPandocLua, unPandocLua)
@@ -92,23 +87,12 @@ documentedModule = Module
-- results of the function call after that.
silence :: LuaE PandocError NumResults
silence = unPandocLua $ do
- -- get current log messages
- origState <- getCommonState
- let origLog = stLog origState
- let origVerbosity = stVerbosity origState
- putCommonState (origState { stLog = [], stVerbosity = ERROR })
-
-- call function given as the first argument
- liftPandocLua $ do
+ ((), messages) <- runSilently . liftPandocLua $ do
nargs <- (NumArgs . subtract 1 . fromStackIndex) <$> gettop
call @PandocError nargs multret
- -- restore original log messages
- newState <- getCommonState
- let newLog = stLog newState
- putCommonState (newState { stLog = origLog, stVerbosity = origVerbosity })
-
liftPandocLua $ do
- pushPandocList pushLogMessage newLog
+ pushPandocList pushLogMessage messages
insert 1
(NumResults . fromStackIndex) <$> gettop
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs
index da666779a..0e21c6340 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs
@@ -18,8 +18,7 @@ import Data.Version (makeVersion)
import HsLua ( LuaE, DocumentedFunction, Module (..)
, (<#>), (###), (=#>), (=?>), (#?), defun, functionResult
, opt, parameter, since, stringParam, textParam)
-import Text.Pandoc.Class ( CommonState (..), fetchItem, fillMediaBag
- , getMediaBag, modifyCommonState, setMediaBag)
+import Text.Pandoc.Class ( fetchItem, fillMediaBag, getMediaBag, setMediaBag )
import Text.Pandoc.Class.IO (writeMedia)
import Text.Pandoc.Error (PandocError)
import Text.Pandoc.Lua.Marshal.Pandoc (peekPandoc, pushPandoc)
@@ -71,8 +70,9 @@ documentedModule = Module
-- | Delete a single item from the media bag.
delete :: DocumentedFunction PandocError
delete = defun "delete"
- ### (\fp -> unPandocLua $ modifyCommonState
- (\st -> st { stMediaBag = MB.deleteMedia fp (stMediaBag st) }))
+ ### (\fp -> unPandocLua $ do
+ mb <- getMediaBag
+ setMediaBag $ MB.deleteMedia fp mb)
<#> stringParam "filepath"
("Filename of the item to deleted. The media bag will be " <>
"left unchanged if no entry with the given filename exists.")
@@ -82,7 +82,7 @@ delete = defun "delete"
-- | Delete all items from the media bag.
empty :: DocumentedFunction PandocError
empty = defun "empty"
- ### unPandocLua (modifyCommonState (\st -> st { stMediaBag = mempty }))
+ ### unPandocLua (setMediaBag mempty)
=#> []
#? "Clear-out the media bag, deleting all items."