Module:List

local utilsArg = require("Module:UtilsArg") local utilsMarkup = require("Module:UtilsMarkup") local utilsString = require("Module:UtilsString") local utilsTable = require("Module:UtilsTable")

local p = {}

function p.Main(frame) local args = utilsTable.merge(frame:getParent.args, frame.args) return p.main(args) end

function p.main(args) local errCategories = utilsArg.validate(args, {			type = {			enum = { "", "*", "#", "inline" },		},	})

local type = args.type local delim = args.delim local items = utilsTable.map(args, utilsString.trim) items = utilsTable.filter(items, utilsString.notEmpty) if not type then return utilsMarkup.list(items) end if type == "*" then return utilsMarkup.bulletList(items) end if type == "#" then return utilsMarkup.numberList(items) end if type == "inline" and delim then return table.concat(items, mw.getCurrentFrame:preprocess(delim)) end return mw.text.listToText(items) .. (errCategories and utilsMarkup.categories(errCategories) or "") end

-- TODO: WIP p.Templates = { List = { purpose = "This outputs bits of text in lists of various formats. It is important that this be used instead of makings lists instead of  so that the output HTML is semantically meaningful to screen readers (that is to say, easier for the visually impaired to navigate.)", params = { type = { type = "string", enum = {"*", "#", "inline"}, desc = "Determines the list format. One of:  (bulleted list), # (numbered list),   (sentence list). If not specified, the list items are simply printed one per line.", },			delim = { type = "string", desc = "If  is , then   sets the separator between each list item. If not specified, the inline list is printed as a phrase.", },			["..."] = {				name = "listItems", placeholder = "listItem", type = "content", desc = "List items. Can be any wikitext.", },		}	} }

return p