From 849900c516f2aab60c675ae46dc87140165ef1da Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 20 Nov 2017 18:37:40 +0100 Subject: 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 --- test/lua/attr-test.lua | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test/lua/attr-test.lua (limited to 'test/lua') 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 -- cgit v1.2.3