Module:UtilsMarkup/List

local p = {}

local utilsTable = require("Module:UtilsTable")

function list(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 .. list(prefix, subprefix, level + 1)(item) else output = output .. itemPrefix .. item end end return output .. (level == 0 and "\n" or "") end end

p.list = list("", ":") p.bulletList = list("*") p.numberList = list("#")

p.Documentation = { {		wip = true, 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 = "\n", },			{				args = { { "single item" } },				expected = "\n*single item\n", },			{				args = { { "multiple", "items", "" }, },				expected = 					*multiple					*items					* },			{				args = { {						"list", {							"with", {"nested", "items"}, "inside" },					},				},				expected = 					*list					**with					***nested					***items					**inside },		}	} } return p