aboutsummaryrefslogtreecommitdiff
path: root/test/lua
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert+github@zeitkraut.de>2017-11-20 18:37:40 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-11-20 09:37:40 -0800
commit849900c516f2aab60c675ae46dc87140165ef1da (patch)
treee97f2a41003950846dcbe313a4ac52f9a45f33e6 /test/lua
parent97efed8c23414bd85801538de7df42b9f38d1fe7 (diff)
downloadpandoc-849900c516f2aab60c675ae46dc87140165ef1da.tar.gz
data/pandoc.lua: enable table-like behavior of attributes (#4080)
Attribute lists are represented as associative lists in Lua. Pure associative lists are awkward to work with. A metatable is attached to attribute lists, allowing to access and use the associative list as if the attributes were stored in as normal key-value pair in table. Note that this changes the way `pairs` works on attribute lists. Instead of producing integer keys and two-element tables, the resulting iterator function now returns the key and value of those pairs. Use `ipairs` to get the old behavior. Warning: the new iteration mechanism only works if pandoc has been compiled with Lua 5.2 or later (current default: 5.3). The `pandoc.Attr` function is altered to allow passing attributes as key-values in a normal table. This is more convenient than having to construct the associative list which is used internally. Closes #4071
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/attr-test.lua6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/lua/attr-test.lua b/test/lua/attr-test.lua
new file mode 100644
index 000000000..68dc0012d
--- /dev/null
+++ b/test/lua/attr-test.lua
@@ -0,0 +1,6 @@
+function Div (div)
+ div.attributes.five = ("%d"):format(div.attributes.two + div.attributes.three)
+ div.attributes.two = nil
+ div.attributes.one = "eins"
+ return div
+end