diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2019-09-15 21:11:58 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-09-15 12:11:58 -0700 |
commit | d0261d7387cdf1a910a1029a747e239453190f71 (patch) | |
tree | f420021bdd6dc101054c5c9f17095cc8bf0620c8 /doc/lua-filters.md | |
parent | f580da203382efbb3c1cc8da37eacd27025034d7 (diff) | |
download | pandoc-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 'doc/lua-filters.md')
-rw-r--r-- | doc/lua-filters.md | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md index 87071ffc4..723f3cd08 100644 --- a/doc/lua-filters.md +++ b/doc/lua-filters.md @@ -1247,7 +1247,19 @@ Superscripted text ### Attr {#type-ref-Attr} -A set of element attributes +A set of element attributes. Values of this type can be created +with the [`pandoc.Attr`](#Attr) constructor. For convenience, it +is usually not necessary to construct the value directly if it is +part of an element, and it is sufficient to pass an HTML-like +table. E.g., to create a span with identifier "text" and classes +"a" and "b", on can write: + + local span = pandoc.Span('text', {id = 'text', class = 'a b'}) + +This also works when using the `attr` setter: + + local span = pandoc.Span 'text' + span.attr = {id = 'text', class = 'a b', other_attribute = '1'} Object equality is determined via [`pandoc.utils.equals`](#utils-equals). |