Module:UtilsMarkup/List

local p = {}

local utilsTable = require("Module:UtilsTable")

local function tag(tag, content, attributes) if not tag then return content end local html = mw.html.create(tag) :attr(attributes or {}) :wikitext(mw.getCurrentFrame:preprocess(content)) return tostring(html) end

local function tagList(listTag, itemTag, listAttributes, level) level = level or 1 return function(items) listAttributes = utilsTable.merge(listAttributes or {}, { -- backwards compatibility for a previous API			start = items.start 		}) if #items == 0 then return "" end local list = "" for _, item in ipairs(items) do			if utilsTable.isArray(item) then list = list .. tagList(listTag, itemTag, listAttributes, level + 1)(item) else list = list .. tag(itemTag, item) end end return tag(listTag, list, listAttributes) end end

function p.list(items) return tagList("ul", "li", {		class = "plainlist"	})(items) end

function p.bulletList(items, attributes) return tagList("ul", "li", attributes)(items) end

function p.numberList(items, attributes) return tagList("ol", "li", attributes)(items) end

function p.definitionList(items, attributes, level) level = level or 1 local listItems = {} for _, definitions in ipairs(items) do		local dt = definitions[1] if dt then table.insert(listItems, tag("dt", dt or "")) end for i = 2, table.maxn(definitions) do			local dd = definitions[i] if type(dd) == "table" then dd = p.definitionList(dd, attributes, level + 1) end table.insert(listItems, tag("dd", dd or "")) end end local list = tagList("dl", nil, attributes, level)(listItems) return list end return p