git.iko.soy/typeable/pandoc
on master help sign in
docs/lua-filters.md: clarify filter function execution order (#6059)
commit467ea4e02cbf09e47c619e59496a3b71142b9710 authorAlbert Krewinkel <albert@zeitkraut.de> dateSat 11 Jan 2020, 00:19 (7 years ago) parent42b915e
1 file changed+30−2
doc/lua-filters.md+30−2
doc/lua-filters.md+30−2
@@ -2,7 +2,7 @@
22author:
33- Albert Krewinkel
44- John MacFarlane
5−date: 'December 6, 2017'
5+date: 'January 10, 2020'
66title: Pandoc Lua Filters
77---
88
@@ -28,7 +28,7 @@ in JSON form. One cannot simply provide a filter that can be
2828used by anyone who has a certain version of the pandoc
2929executable.
3030
31−Starting with pandoc 2.0, we have made it possible to write
31+Starting with version 2.0, pandoc makes it possible to write
3232filters in lua without any external dependencies at all. A lua
3333interpreter (version 5.3) and a lua library for creating pandoc
3434filters is built into the pandoc executable. Pandoc data types
@@ -136,6 +136,34 @@ Elements without matching functions are left untouched.
136136See [module documentation](#module-pandoc) for a list of pandoc
137137elements.
138138
139+## Execution order
140+
141+Element filter functions within a filter set are called in a
142+fixed order, skipping any which are not present:
143+
144+ 1. functions for [*Inline* elements](#type-ref-Inline),
145+ 2. functions for [*Block* elements](#type-ref-Block) ,
146+ 3. the [*Meta*](#type-ref-Meta) filter function, and last
147+ 4. the [*Pandoc*](#type-ref-Meta) filter function.
148+
149+It is still possible to force a different order by explicitly
150+returning multiple filter sets. For example, if the filter for
151+*Meta* is to be run before that for *Str*, one can write
152+
153+``` lua
154+-- ... filter definitions ...
155+
156+return {
157+ { Meta = Meta }, -- (1)
158+ { Str = Str } -- (2)
159+}
160+```
161+
162+Filter sets are applied in the order in which they are returned.
163+All functions in set (1) are thus run before those in (2),
164+causing the filter function for *Meta* to be run before the
165+filtering of *Str* elements is started.
166+
139167## Global variables
140168
141169Pandoc passes additional data to Lua filters by setting global