summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2022-06-06 18:25:09 +0200
committerGitHub <noreply@github.com>2022-06-06 09:25:09 -0700
commitb2b21bb4c54e5aae305a0166c044357023e38abd (patch)
tree34e08924a05a11d2a11fd34dcbebe43eec475157 /src
parente5c41f11de39d71241bdaf4cc9cd6890846db742 (diff)
Lua: add function pandoc.mediabag.fill (#8104)
The function allows to fill the mediabag with all images in a given document. Images that cannot be fetched are replaced with a Span containing the image description.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Lua/Module/MediaBag.hs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Lua/Module/MediaBag.hs b/src/Text/Pandoc/Lua/Module/MediaBag.hs
index 8be668089..72e7ff00d 100644
--- a/src/Text/Pandoc/Lua/Module/MediaBag.hs
+++ b/src/Text/Pandoc/Lua/Module/MediaBag.hs
@@ -15,12 +15,13 @@ module Text.Pandoc.Lua.Module.MediaBag
import Prelude hiding (lookup)
import Data.Maybe (fromMaybe)
import HsLua ( LuaE, DocumentedFunction, Module (..)
- , (<#>), (###), (=#>), (=?>), defun, functionResult
+ , (<#>), (###), (=#>), (=?>), (#?), defun, functionResult
, opt, parameter, stringParam, textParam)
import Text.Pandoc.Class.CommonState (CommonState (..))
-import Text.Pandoc.Class.PandocMonad (fetchItem, getMediaBag, modifyCommonState,
- setMediaBag)
+import Text.Pandoc.Class.PandocMonad (fetchItem, fillMediaBag, getMediaBag,
+ modifyCommonState, setMediaBag)
import Text.Pandoc.Error (PandocError)
+import Text.Pandoc.Lua.Marshal.Pandoc (peekPandoc, pushPandoc)
import Text.Pandoc.Lua.Marshal.List (pushPandocList)
import Text.Pandoc.Lua.Orphans ()
import Text.Pandoc.Lua.PandocLua (unPandocLua)
@@ -42,6 +43,7 @@ documentedModule = Module
[ delete
, empty
, fetch
+ , fill
, insert
, items
, list
@@ -65,6 +67,21 @@ empty = defun "empty"
### unPandocLua (modifyCommonState (\st -> st { stMediaBag = mempty }))
=#> []
+-- | Fill the mediabag with all images in the document that aren't
+-- present yet.
+fill :: DocumentedFunction PandocError
+fill = defun "fill"
+ ### unPandocLua . fillMediaBag
+ <#> parameter peekPandoc "Pandoc" "doc"
+ "document from which to fill the mediabag"
+ =#> functionResult pushPandoc "Pandoc" "modified document"
+ #? ("Fills the mediabag with the images in the given document.\n" <>
+ "An image that cannot be retrieved will be replaced with a Span\n" <>
+ "of class \"image\" that contains the image description.\n" <>
+ "" <>
+ "Images for which the mediabag already contains an item will\n" <>
+ "not be processed again.")
+
-- | Insert a new item into the media bag.
insert :: DocumentedFunction PandocError
insert = defun "insert"