git.iko.soy/typeable/pandoc
on master help sign in
data/pandoc.lua: add datatype ListAttributes
5f6f2c6Albert Krewinkel
data/pandoc.lua+29−1
@@ -403,7 +403,7 @@ M.Null = M.Block:create_constructor(
403M.OrderedList = M.Block:create_constructor(
403M.OrderedList = M.Block:create_constructor(
404 "OrderedList",
404 "OrderedList",
405 function(items, listAttributes)
405 function(items, listAttributes)
406− listAttributes = listAttributes or {1, M.DefaultStyle, M.DefaultDelim}
406+ listAttributes = listAttributes or M.ListAttributes()
407 return {c = {listAttributes, ensureList(items)}}
407 return {c = {listAttributes, ensureList(items)}}
408 end,
408 end,
409 {{listAttributes = {"start", "style", "delimiter"}}, "content"}
409 {{listAttributes = {"start", "style", "delimiter"}}, "content"}
@@ -857,6 +857,34 @@ function M.Citation:new (id, mode, prefix, suffix, note_num, hash)
857 }
857 }
858end
858end
859
859
860+-- ListAttributes
861+M.ListAttributes = AstElement:make_subtype 'ListAttributes'
862+
863+--- Creates a set of list attributes.
864+-- @function ListAttributes
865+-- @tparam[opt] integer start number of the first list item
866+-- @tparam[opt] string style style used for list numbering
867+-- @tparam[opt] DefaultDelim|Period|OneParen|TwoParens delimiter delimiter of list numbers
868+-- @treturn table list attributes table
869+function M.ListAttributes:new (start, style, delimiter)
870+ start = start or 1
871+ style = style or 'DefaultStyle'
872+ delimiter = delimiter or 'DefaultDelim'
873+ return {start, style, delimiter}
874+end
875+M.ListAttributes.behavior._field_names = {start = 1, style = 2, delimiter = 3}
876+M.ListAttributes.behavior.__index = function (t, k)
877+ return rawget(t, getmetatable(t)._field_names[k]) or
878+ getmetatable(t)[k]
879+end
880+M.ListAttributes.behavior.__newindex = function (t, k, v)
881+ if getmetatable(t)._field_names[k] then
882+ rawset(t, getmetatable(t)._field_names[k], v)
883+ else
884+ rawset(t, k, v)
885+ end
886+end
887+
860
888
861------------------------------------------------------------------------
889------------------------------------------------------------------------
862-- Constants
890-- Constants
doc/lua-filters.md+17
@@ -1253,6 +1253,23 @@ Lua functions for pandoc scripts.
1253 `hash`:
1253 `hash`:
1254 : hash number
1254 : hash number
1255
1255
1256+[`ListAttributes ([start[, style[, delimiter]]])`](#ListAttributes)
1257+
1258+: Creates a set of list attributes
1259+
1260+ Parameters:
1261+
1262+ `start`:
1263+ : number of the first list item (default: 1)
1264+
1265+ `style`:
1266+ : style used for list numbering (default: `DefaultStyle`)
1267+
1268+ `delimiter`:
1269+ : delimiter of list numbers (default: `DefaultDelim`)
1270+
1271+ Returns: list attributes table
1272+
1256## Constants
1273## Constants
1257
1274
1258[`AuthorInText`]{#AuthorInText}
1275[`AuthorInText`]{#AuthorInText}