aboutsummaryrefslogtreecommitdiff
path: root/doc/lua-filters.md
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2026-01-02 13:30:47 +0100
committerJohn MacFarlane <[email protected]>2026-01-02 11:10:09 -0500
commit8f8ea44d02b6a3ca0c3e80eaf78e926889f29c9b (patch)
treed5c93a91e98838bcb916f24b8ca8b97fbc09d699 /doc/lua-filters.md
parente8d140f41feb0ad023c0b7f22355fec96207dfee (diff)
Lua: add function `pandoc.with_state`
The function allows to run a callback with a modified pandoc state. This provides the ability to temporarily modify the resource path, the user data directory, and the HTTP request headers. Closes: #10859
Diffstat (limited to 'doc/lua-filters.md')
-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 a6521b9f7..2c82447f9 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -3890,6 +3890,33 @@ Parameters:
Returns: the transformed inline element
+### `with_state (options, callback)` {#pandoc.with_state}
+
+Runs a function with a modified pandoc state.
+
+The given callback is invoked after setting the pandoc state to the
+given values. The modifiable options are restored to their original
+values once the callback has returned.
+
+The following state variables can be controlled:
+
+ - `request_headers` (list of key-value tuples)
+ - `resource_path` (list of filepaths)
+ - `user_data_dir` (string)
+
+Other options are ignored, and the rest of the state is not modified.
+
+Usage:
+
+ local opts = {
+ request_headers = {
+ {'Authorization', 'Basic my-secret'}
+ }
+ }
+ pandoc.with_state(opts, function ()
+ local mime, contents = pandoc.mediabag.fetch(image_url)
+ )
+
### `read (markup[, format[, reader_options[, read_env]]])` {#pandoc.read}
Parse the given string into a Pandoc document.