aboutsummaryrefslogtreecommitdiff
path: root/doc/lua-filters.md
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-12-29 08:37:19 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2017-12-29 08:37:19 -0800
commit4962220315d5e2c429ab63f558381528e808eafd (patch)
treeb9aa106be12d34f353e85ada351cebd24b94dd2f /doc/lua-filters.md
parent37778077debda3b1af80be92728c3a675f8ed384 (diff)
parent76442a791c4db9df43792dbd3733272607d4586e (diff)
downloadpandoc-4962220315d5e2c429ab63f558381528e808eafd.tar.gz
Merge branch 'master' of github.com:jgm/pandoc
Diffstat (limited to 'doc/lua-filters.md')
-rw-r--r--doc/lua-filters.md91
1 files changed, 67 insertions, 24 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index c99625e67..dfd92a35b 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -1172,18 +1172,6 @@ Lua functions for pandoc scripts.
Returns: strong element
-## Helpers
-
-[`apairs (value)`]{#apairs}
-
-: Return an iterator which returns key-value pairs of an
- associative list.
-
- Parameters:
-
- `value`:
- : },\...} alist associative list
-
[`Attr ([identifier[, classes[, attributes]]])`]{#Attr}
: Create a new set of attributes (Attr).
@@ -1335,25 +1323,80 @@ Lua functions for pandoc scripts.
See also: [OrderedList](#OrderedList)
-## Helper Functions
+## Helper functions
+
+[`pipe (command, args, input)`]{#pipe}
+
+: Runs command with arguments, passing it some input, and
+ returns the output.
+
+ Returns:
-[`global_filter ()`]{#global_filter}
+ - Output of command.
-: Use functions defined in the global namespace to create a
- pandoc filter.
+ Raises:
- Returns: A list of filter functions
+ - A table containing the keys `command`, `error_code`, and
+ `output` is thrown if the command exits with a non-zero
+ error code.
Usage:
- -- within a file defining a pandoc filter:
- function Str(text)
- return pandoc.Str(utf8.upper(text))
- end
+ local output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc")
+
+[`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.
+
+ Parameters:
+
+ `markup`:
+ : the markup to be parsed
+
+ `format`:
+ : format specification, defaults to \"markdown\".
+
+ Returns: pandoc document
+
+ Usage:
- return {pandoc.global_filter()}
- -- the above is equivallent to
- -- return {{Str = Str}}
+ local org_markup = "/emphasis/" -- Input to be read
+ local document = pandoc.read(org_markup, "org")
+ -- Get the first block of the document
+ local block = document.blocks[1]
+ -- The inline element in that block is an `Emph`
+ assert(block.content[1].t == "Emph")
# Module pandoc.utils