aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2019-02-15 17:13:04 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2019-05-29 23:17:12 +0200
commit3097ee100ed260a5c2cea7df5bf80c989687df44 (patch)
treee42fc606fb96b93f09422203470013b9b825832c /doc
parent8507d98a1534ba4049e4c1ca3671ee41a1f56c70 (diff)
downloadpandoc-3097ee100ed260a5c2cea7df5bf80c989687df44.tar.gz
pandoc.mediabag module: add items function iterating over mediabag
A new function `pandoc.mediabag.items` was added to Lua module pandoc.mediabag. This allows users to lazily iterate over all media bag items, loading items into Lua one-by-one. Example: for filename, mime_type, content in pandoc.mediabag.items() do -- use media bag item. end This is a convenient alternative to using `mediabag.list` in combination with `mediabag.lookup`.
Diffstat (limited to 'doc')
-rw-r--r--doc/lua-filters.md27
1 files changed, 27 insertions, 0 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index 45abe8ac8..667a58bcc 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -2475,6 +2475,33 @@ Usage:
local contents = "Hello, World!"
pandoc.mediabag(fp, mt, contents)
+### iter {#mediabag-iter}
+
+`items ()`
+
+Returns an iterator triple to be used with Lua's generic `for`
+statement. The iterator returns the filepath, MIME type, and
+content of a media bag item on each invocation. Items are
+processed one-by-one to avoid excessive memory use.
+
+This function should be used only when full access to all items,
+including their contents, is required. For all other cases,
+[`list`](#mediabag-list) should be preferred.
+
+Returns:
+
+ - The iterator function; must be called with the iterator state
+ and the current iterator value.
+ - Iterator state – an opaque value to be passed to the iterator
+ function.
+ - Initial iterator value.
+
+Usage:
+
+ for fp, mt, contents in pandoc.mediabag.items() do
+ -- print(fp, mt, contents)
+ end
+
### list {#mediabag-list}
`list ()`