aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2017-12-06 20:45:38 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2017-12-06 22:50:56 +0100
commit4066a385ace1cee53336bf4c10734239044a92ae (patch)
tree1ed8d3bb1201f298840c53ae8e72bf4afa8f8ad9 /doc
parentd5b1c7b767a24bda592ea35902b8e1dc971d6d80 (diff)
downloadpandoc-4066a385ace1cee53336bf4c10734239044a92ae.tar.gz
Lua filters: use script to initialize the interpreter
The file `init.lua` is used to initialize the Lua interpreter which is used in Lua filters. This gives users the option to require libraries which they want to use in all of their filters, and to extend default modules.
Diffstat (limited to 'doc')
-rw-r--r--doc/lua-filters.md30
1 files changed, 29 insertions, 1 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index 11643da84..9beeda185 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -3,7 +3,7 @@ title: Pandoc Lua Filters
author:
- Albert Krewinkel
- John MacFarlane
-date: 'November 20, 2017'
+date: 'December 6, 2017'
---
# Introduction
@@ -176,6 +176,34 @@ Some pandoc functions have been made available in lua:
which stores binary content such as images that may be
included in the final document.
+# Lua interpreter initialization
+
+The way the Lua interpreter is set-up can be controlled by
+placing a file `init.lua` in pandoc's data directory. The
+default init file loads the `pandoc` and `pandoc.mediabag`
+modules:
+
+``` lua
+pandoc = require 'pandoc'
+pandoc.mediabag = require 'pandoc.mediabag'
+```
+
+A common use-case would be to add code to load additional
+modules or to alter default modules. E.g., the following snippet
+adds all unicode-aware functions defined in the [`text`
+module](#module-text) to the default `string` module, prefixed
+with the string `uc_`.
+
+```lua
+for name, fn in pairs(require 'text') do
+ string['uc_' .. name] = fn
+end
+```
+
+This makes it possible to apply these functions on strings using
+colon syntax (`mystring:uc_upper()`).
+
+
# Examples
## Macro substitution.