From 0a6a11cfabead239eab3baec065d8d6e95bb6447 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel <albert@zeitkraut.de> Date: Sat, 16 Feb 2019 13:20:33 +0100 Subject: [PATCH] pandoc.mediabag module: add function `empty` Function `pandoc.mediabag.empty` was added. It allows to clean-out the media bag, removing all entries. --- doc/lua-filters.md | 7 ++++++- src/Text/Pandoc/Lua/Module/MediaBag.hs | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/lua-filters.md b/doc/lua-filters.md index 667a58bcc..d60957a2e 100644 --- a/doc/lua-filters.md +++ b/doc/lua-filters.md @@ -2448,9 +2448,14 @@ The module is loaded as part of module `pandoc` and can either be accessed via the `pandoc.mediabag` field, or explicitly required, e.g.: - local mb = require 'pandoc.mediabag' +### empty {#mediabag-empty} + +`empty ()` + +Clear-out the media bag, deleting all items. + ### insert {#mediabag-insert} `insert (filepath, mime_type, contents)` diff --git a/src/Text/Pandoc/Lua/Module/MediaBag.hs b/src/Text/Pandoc/Lua/Module/MediaBag.hs index ce6303ec6..4678d46e8 100644 --- a/src/Text/Pandoc/Lua/Module/MediaBag.hs +++ b/src/Text/Pandoc/Lua/Module/MediaBag.hs @@ -34,6 +34,7 @@ import qualified Text.Pandoc.MediaBag as MB pushModule :: Lua NumResults pushModule = do Lua.newtable + addFunction "empty" empty addFunction "insert" insertMediaFn addFunction "items" items addFunction "lookup" lookupMediaFn @@ -60,6 +61,11 @@ setCommonState st = do modifyCommonState :: (CommonState -> CommonState) -> Lua () modifyCommonState f = getCommonState >>= setCommonState . f +-- | Delete all items from the media bag. +empty :: Lua NumResults +empty = 0 <$ modifyCommonState (\st -> st { stMediaBag = mempty }) + +-- | Insert a new item into the media bag. insertMediaFn :: FilePath -> Optional MimeType -> BL.ByteString