Module:UtilsMarkup/List

local p = {}

local utilsTable = require("Module:UtilsTable")

local function prefixList(prefix, subprefix, level) level = level or 0 local itemPrefix = "\n" .. prefix .. string.rep(subprefix or prefix, level) return function(items) local output = "" for i, item in ipairs(items or {}) do			if utilsTable.isArray(item) then output = output .. prefixList(prefix, subprefix, level + 1)(item) else output = output .. itemPrefix .. item end end return output .. (level == 0 and "\n" or "") end end

local function tag(tag, content, attributes) if attributes or styles then return tostring(mw.html.create(tag)			:attr(attributes)			:wikitext(mw.getCurrentFrame:preprocess(content))		) end return ("%s"):format(tag, content, tag) end

local function tagList(listTag, itemTag) return function(items) local listAttributes = { 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)(item) else list = list .. tag(itemTag, item) end end return tag(listTag, list, listAttributes) .. "\n" end end

p.list = prefixList("", ":") p.bulletList = tagList("ul", "li") p.numberList = tagList("ol", "li")

p.Documentation = { {		name = "list", params = { {				name = "items", description = "list items", }		},		returns = "A multiline string with each item on its own line.", cases = { {				args = { {} }, expected = "\n", },			{				args = { { "single item" } },				expected = "\nsingle item\n", },			{				args = { { "multiple", "items", "" }, },				expected = "\nmultiple\nitems\n\n" },			{				args = { {						"list", {							"with", {"nested", "items"}, "inside" },					},				},				expected = 					list					:with					::nested					::items					:inside },		}	},	{		name = "bulletList", params = { {				name = "items", description = "list items", },		},		returns = "A string representation of an unordered list in wikitext", cases = { {				args = { {} }, expected = "", },			{				args = { { "single item" } },				expected = "single item\n", },			{				args = { { "multiple", "items", "" }, },				expected = "multipleitems\n", },			{				args = { {						"list", {							"with", {"nested", "items"}, "inside" },					},				},				expected = "listwith</li>nested</li>items</li></ul>\ninside</li></ul>\n</ul>\n" },		}	},	{		name = "numberList", params = { {				name = "items", description = "list items", },		},		returns = "A string representation of an ordered list in wikitext", cases = { {				args = { {} }, expected = "", },			{				args = { { "single item" } },				expected = "<ol>single item</li></ol>\n", },			{				args = { { "multiple", "items", "" }, },				expected = "<ol>multiple</li>items</li></li></ol>\n" },			{				args = { {						"list", {							"with", {"nested", "items"}, "inside" },					},				},				expected = "<ol>list</li><ol>with</li><ol>nested</li>items</li></ol>\ninside</li></ol>\n</ol>\n" },			{				args = { {						start = 8, "Eight", "Nine", "Ten" },				},				expected = ' <li>Eight</li><li>Nine</li><li>Ten</li></ol>\n', },		}	} } return p