Lua filters: make attr argument optional in Table constructor

This changes the Lua API. It is highly unlikely for this change to
affect existing filters, since the documentation for the new Table
constructor (and type) was incomplete and partly wrong before.

The Lua API is now more consistent, as all constructors for elements
with attributes now take attributes as the last parameter.
This commit is contained in:
Albert Krewinkel 2020-07-25 20:29:21 +02:00
parent 9dd4d077c0
commit 44c4660a31
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
3 changed files with 19 additions and 10 deletions

View file

@ -556,18 +556,18 @@ M.RawBlock = M.Block:create_constructor(
--- Creates a table element. --- Creates a table element.
-- @function Table -- @function Table
-- @tparam Attr attr attributes
-- @tparam Caption caption table caption -- @tparam Caption caption table caption
-- @tparam {ColSpec,...} colspecs column alignments and widths -- @tparam {ColSpec,...} colspecs column alignments and widths
-- @tparam TableHead head table head -- @tparam TableHead head table head
-- @tparam {TableBody,..} bodies table bodies -- @tparam {TableBody,..} bodies table bodies
-- @treturn TableFoot foot table foot -- @treturn TableFoot foot table foot
-- @tparam[opt] Attr attr attributes
M.Table = M.Block:create_constructor( M.Table = M.Block:create_constructor(
"Table", "Table",
function(attr, caption, colspecs, head, bodies, foot) function(caption, colspecs, head, bodies, foot, attr)
return { return {
c = { c = {
attr, ensureAttr(attr),
caption, caption,
List:new(colspecs), List:new(colspecs),
head, head,

View file

@ -1104,6 +1104,9 @@ Values of this type can be created with the
Fields: Fields:
`attr`
: table attributes ([Attr])
`caption` `caption`
: table caption ([Caption]) : table caption ([Caption])
@ -1120,8 +1123,14 @@ Fields:
`foot` `foot`
: table foot ([TableFoot]) : table foot ([TableFoot])
`attr` `identifier`
: element attributes ([Attr]) : alias for `attr.identifier` (string)
`classes`
: alias for `attr.classes` ([List] of strings)
`attributes`
: alias for `attr.attributes` ([Attributes])
`tag`, `t` `tag`, `t`
: the literal `Table` (string) : the literal `Table` (string)
@ -2144,15 +2153,12 @@ format, and functions to filter and modify a subtree.
Returns: [RawBlock](#type-rawblock) object Returns: [RawBlock](#type-rawblock) object
[`Table (attr, caption, colspecs, head, bodies, foot)`]{#pandoc.table} [`Table (caption, colspecs, head, bodies, foot[, attr])`]{#pandoc.table}
: Creates a table element. : Creates a table element.
Parameters: Parameters:
`attr`:
: element attributes
`caption`: `caption`:
: table [caption](#type-caption) : table [caption](#type-caption)
@ -2168,6 +2174,9 @@ format, and functions to filter and modify a subtree.
`foot`: `foot`:
: [table foot](#type-tablefoot) : [table foot](#type-tablefoot)
`attr`:
: element attributes
Returns: [Table](#type-table) object Returns: [Table](#type-table) object
## Inline ## Inline

View file

@ -170,7 +170,7 @@ pushBlock = \case
Plain blcks -> pushViaConstructor "Plain" blcks Plain blcks -> pushViaConstructor "Plain" blcks
RawBlock f cs -> pushViaConstructor "RawBlock" f cs RawBlock f cs -> pushViaConstructor "RawBlock" f cs
Table attr blkCapt specs thead tbody tfoot -> Table attr blkCapt specs thead tbody tfoot ->
pushViaConstructor "Table" attr blkCapt specs thead tbody tfoot pushViaConstructor "Table" blkCapt specs thead tbody tfoot attr
-- | Return the value at the given index as block if possible. -- | Return the value at the given index as block if possible.
peekBlock :: StackIndex -> Lua Block peekBlock :: StackIndex -> Lua Block