aboutsummaryrefslogtreecommitdiff
path: root/test/lua
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2019-09-15 21:11:58 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2019-09-15 12:11:58 -0700
commitd0261d7387cdf1a910a1029a747e239453190f71 (patch)
treef420021bdd6dc101054c5c9f17095cc8bf0620c8 /test/lua
parentf580da203382efbb3c1cc8da37eacd27025034d7 (diff)
downloadpandoc-d0261d7387cdf1a910a1029a747e239453190f71.tar.gz
Lua filters: allow passing of HTML-like tables instead of Attr (#5750)
Attr values can now be given as normal Lua tables; this can be used as a convenient alternative to define Attr values, instead of constructing values with `pandoc.Attr`. Identifiers are taken from the *id* field, classes must be given as space separated words in the *class* field. All remaining fields are included as misc attributes. With this change, the following lines now create equal elements: pandoc.Span('test', {id = 'test', class = 'a b', check = 1}) pandoc.Span('test', pandoc.Attr('test', {'a','b'}, {check = 1})) This also works when using the *attr* setter: local span = pandoc.Span 'text' span.attr = {id = 'test', class = 'a b', check = 1} Furthermore, the *attributes* field of AST elements can now be a plain key-value table even when using the `attributes` accessor: local span = pandoc.Span 'test' span.attributes = {check = 1} -- works as expected now Closes: #5744
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/module/pandoc.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/lua/module/pandoc.lua b/test/lua/module/pandoc.lua
index 1725d275b..fa1748c18 100644
--- a/test/lua/module/pandoc.lua
+++ b/test/lua/module/pandoc.lua
@@ -86,6 +86,47 @@ return {
assert.are_equal(count, 3)
end)
},
+ group 'HTML-like attribute tables' {
+ test('in element constructor', function ()
+ local html_attributes = {
+ id = 'the-id',
+ class = 'class1 class2',
+ width = '11',
+ height = '12'
+ }
+ local attr = pandoc.Span('test', html_attributes).attr
+ assert.are_equal(attr.identifier, 'the-id')
+ assert.are_equal(attr.classes[1], 'class1')
+ assert.are_equal(attr.classes[2], 'class2')
+ assert.are_equal(attr.attributes.width, '11')
+ assert.are_equal(attr.attributes.height, '12')
+ end),
+ test('element attr setter', function ()
+ local html_attributes = {
+ id = 'the-id',
+ class = 'class1 class2',
+ width = "11",
+ height = "12"
+ }
+ local span = pandoc.Span 'test'
+ span.attr = html_attributes
+ assert.are_equal(span.attr.identifier, 'the-id')
+ assert.are_equal(span.attr.classes[1], 'class1')
+ assert.are_equal(span.attr.classes[2], 'class2')
+ assert.are_equal(span.attr.attributes.width, '11')
+ assert.are_equal(span.attr.attributes.height, '12')
+ end),
+ test('element attrbutes setter', function ()
+ local attributes = {
+ width = "11",
+ height = "12"
+ }
+ local span = pandoc.Span 'test'
+ span.attributes = attributes
+ assert.are_equal(span.attr.attributes.width, '11')
+ assert.are_equal(span.attr.attributes.height, '12')
+ end)
+ }
},
group 'clone' {