summaryrefslogtreecommitdiff
path: root/doc/lua-filters.md
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-11-11 11:01:38 -0500
committerJohn MacFarlane <jgm@berkeley.edu>2017-11-11 14:41:11 -0800
commit6174b5bea5e8c4c35c191bd62f1f42e4d7fce69e (patch)
tree77c969bad5269afb10a2afd4245e1c3abbb476e0 /doc/lua-filters.md
parent5bedd6219a73113123ebf13f6de43c230386d3ca (diff)
Add lua filter functions to walk inline and block elements.
Refactored some code from Text.Pandoc.Lua.PandocModule into new internal module Text.Pandoc.Lua.Filter. Add `walk_inline` and `walk_block` in pandoc lua module.
Diffstat (limited to 'doc/lua-filters.md')
-rw-r--r--doc/lua-filters.md49
1 files changed, 48 insertions, 1 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index 8c8268c20..1e0b988ba 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -165,6 +165,8 @@ those elements accessible through the filter function parameter.
Some pandoc functions have been made available in lua:
+- `walk_block` and `walk_inline` allow filters to be applied
+ inside specific block or inline elements.
- `read` allows filters to parse strings into pandoc documents
- `pipe` runs an external command with input from and output to
strings
@@ -333,6 +335,20 @@ will output:
</dl>
```
+## Uppercasing text inside all headers
+
+This filter uses `walk_block` to transform inline elements
+inside headers, converting all their text into uppercase.
+
+``` lua
+function Header(el)
+ return pandoc.walk_block(el, {
+ Str = function(el)
+ return pandoc.Str(el.text:upper())
+ end })
+end
+```
+
## Converting ABC code to music notation
This filter replaces code blocks with class `abc` with
@@ -1070,6 +1086,38 @@ Lua functions for pandoc scripts.
## Helper Functions
+[`walk_block (element, filter)`]{#walk_block}
+
+: Apply a filter inside a block element, walking its
+ contents.
+
+ Parameters:
+
+ `element`:
+ : the block element
+
+ `filter`:
+ : a lua filter (table of functions) to be applied
+ within the block element
+
+ Returns: the transformed block element
+
+[`walk_inline (element, filter)`]{#walk_inline}
+
+: Apply a filter inside an inline element, walking its
+ contents.
+
+ Parameters:
+
+ `element`:
+ : the inline element
+
+ `filter`:
+ : a lua filter (table of functions) to be applied
+ within the inline element
+
+ Returns: the transformed inline element
+
[`read (markup[, format])`]{#read}
: Parse the given string into a Pandoc document.
@@ -1142,7 +1190,6 @@ Lua functions for pandoc scripts.
local output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc")
-
# Submodule mediabag
The submodule `mediabag` allows accessing pandoc's media