From 6174b5bea5e8c4c35c191bd62f1f42e4d7fce69e Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Sat, 11 Nov 2017 11:01:38 -0500
Subject: 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.
---
 doc/lua-filters.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

(limited to 'doc')

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
-- 
cgit v1.2.3