pandoc.mediabag module: add function empty

Function `pandoc.mediabag.empty` was added. It allows to clean-out the media
bag, removing all entries.
This commit is contained in:
Albert Krewinkel 2019-02-16 13:20:33 +01:00
parent 3097ee100e
commit 0a6a11cfab
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
2 changed files with 12 additions and 1 deletions

View file

@ -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)`

View file

@ -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