diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2019-02-16 13:35:16 +0100 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2019-05-29 23:18:44 +0200 |
commit | 5a82ecaaa19176afc24576fd80b91c9a529c2dcb (patch) | |
tree | 8c7d4fcca448419987f6327de80cdc71bc3efe87 /src/Text/Pandoc/Lua | |
parent | 0a6a11cfabead239eab3baec065d8d6e95bb6447 (diff) | |
download | pandoc-5a82ecaaa19176afc24576fd80b91c9a529c2dcb.tar.gz |
pandoc.mediabag module: add function `delete`
Function `pandoc.mediabag.delete` allows to remove a single item of the given
name from the media bag.
Diffstat (limited to 'src/Text/Pandoc/Lua')
-rw-r--r-- | src/Text/Pandoc/Lua/Module/MediaBag.hs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Lua/Module/MediaBag.hs b/src/Text/Pandoc/Lua/Module/MediaBag.hs index 4678d46e8..261785665 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 "delete" delete addFunction "empty" empty addFunction "insert" insertMediaFn addFunction "items" items @@ -61,6 +62,11 @@ setCommonState st = do modifyCommonState :: (CommonState -> CommonState) -> Lua () modifyCommonState f = getCommonState >>= setCommonState . f +-- | Delete a single item from the media bag. +delete :: FilePath -> Lua NumResults +delete fp = 0 <$ modifyCommonState + (\st -> st { stMediaBag = MB.deleteMedia fp (stMediaBag st) }) + -- | Delete all items from the media bag. empty :: Lua NumResults empty = 0 <$ modifyCommonState (\st -> st { stMediaBag = mempty }) @@ -86,7 +92,7 @@ lookupMediaFn :: FilePath lookupMediaFn fp = do res <- MB.lookupMedia fp . stMediaBag <$> getCommonState case res of - Nothing -> Lua.pushnil *> return 1 + Nothing -> 1 <$ Lua.pushnil Just (mimeType, contents) -> do Lua.push mimeType Lua.push contents |