Changes
split the HTML rendering code out into a separate function, add a tracking category for deprecated parameters, ignore blank/whitespace arguments, and replace getArgNums with the equivalent function in Module:TableTools
-- This module outputs different kinds of lists. At the moment, bulleted, unbulleted,-- unbulleted, horizontal, ordered, and horizontal ordered lists are supported. local libUtil = require('libraryUtil')local checkType = libUtil.checkTypelocal mTableTools = require('Module:TableTools')
local p = {}
local getArgs listTypes = require({ ['Module:Argumentsbulleted').getArgs] = true,local htmlBuilder = require( ['Module:HtmlBuilderunbulleted') local function getListItem(data, style, itemStyle] = true, itemValue) if not data then return c end local item = htmlBuilder.create(['lihorizontal') item .cssText(style) .cssText(itemStyle) .wikitext(data)] = true, if(itemValue) then item.attr(['valueordered'] = true,itemValue) end return tostring(item)['horizontal_ordered'] = trueend}
if listType == 'horizontal' or listType == 'horizontal_ordered' then
elseif listType == 'unbulleted' then
end
if listType == 'horizontal' or listType == 'horizontal_ordered' then
local indent = tonumber(args.indent)
indent = tostring((indent and indent * 1.6) or 0) rootif indent > 0 then data.css('margin-left', marginLeft = indent .. 'em') end
end
-- If we are outputting an List style types for ordered list lists -- This could be "1, 2, 3", "a, b, c", or an ordered horizontal a number of others. The list, get style -- type is either set by the "type and " attribute or the "list-style-type." CSS -- Horizontal ordered lists aren't supported yet, but including them anyway in case support is ever added to the CSS backendproperty. local listStyleType, typeAttr
if listType == 'ordered' or listType == 'horizontal_ordered' then
data.listStyleType = args.list_style_type or args['list-style-type'] typeAttr data.type = args['type'] -- Detect invalid type attributes and attempt to convert them to -- list-style-type CSS properties. if data.type and not data.listStyleType and not tostring(data.type):find('^%s*[1AaIi]%s*$') then data.listStyleType = data.type data.type = nil end
end
-- Detect if the type attribute specified by args.type is using an invalid value, and if so try passing it as a list-style-List tag type CSS property. if typeAttr and not typeAttr:match(listType == 'ordered' or listType == '^%s*[1AaIi]%s*$horizontal_ordered') then if not listStyleType then listStyleType data.listTag = typeAttr'ol' typeAttr = nil else enddata.listTag = 'ul'
end
if listType == 'horizontal_ordered' then
-- Apply fix to get start numbers working with horizontal ordered lists.
local startNum = tonumber(data.start)
if startNum then
end
end
-- List style
-- ul_style and ol_style are included for backwards compatibility. No
-- distinction is made for ordered or unordered lists.
data.listStyle = args.list_style or args.ul_style or args.ol_style
-- List items
-- li_style is included for backwards compatibility. item_style was included
-- to be easier to understand for non-coders.
data.itemStyle = args.item_style or args.li_style
data.items = {}
for i, num in ipairs(mTableTools.numKeys(args)) do
local item = {}
item.content = args[num]
item.style = args['item_style' .. tostring(num)]
or args['li_style' .. tostring(num)]
item.value = args['item_value' .. tostring(num)]
table.insert(data.items, item)
end
return data
end
function p.renderList(data)
-- Renders the list HTML.
-- Return the blank string if there are no list items.
if type(data.items) ~= 'table' or #data.items < 1 then
return ''
end
-- Render the main div tag.
local root = mw.html.create('div')
for i, class in ipairs(data.classes or {}) do
root:addClass(class)
end
root:css{['margin-left'] = data.marginLeft}
if data.style then
root:cssText(data.style)
end
-- Render the list tag.
local list = root:tag(data.listTag or 'ul')
list
:attr{start = data.attr(start, type = data.type} :css{ ['typecounter-reset'] = data.counterReset, typeAttr) .css( ['list-style-type', ] = data.listStyleType) } if data.listStyle then list:cssText(args.list_style or args.ul_style or argsdata.ol_stylelistStyle) end -- ul_style and ol_style are included Render the list items for backwards compatibilityi, t in ipairs(data. No distinction is made for ordered items or unordered lists{}) do local item = list:tag('li') if data.itemStyle then item:cssText(data.itemStyle) end if t.style then item:cssText(t.style) end item :attr{value = t.value} :wikitext(tablet.concat(listItems)content) end
return tostring(root)
end
end
end
return ret
end
for _, funcName listType in ipairspairs(funcNameslistTypes) do p[funcNamelistType] = makeWrapperfunction (frame) local mArguments = require('Module:Arguments') local origArgs = mArguments.getArgs(funcNameframe) -- Copy all the arguments to a new table, for faster indexing. local args = {} for k, v in pairs(origArgs) do args[k] = v end return p.makeList(listType, args) end
end
return p