Module:List

local p = {}

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

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates.List) if err then utilsMarkup.categories(err.categories) end return p.printList(args.listItems, args.type, args.delim) end

function p.printList(items, type, delim) if items == nil or #items == 0 then return "" end if not type then return utilsMarkup.list(items) elseif type == "*" then return utilsMarkup.bulletList(items) elseif type == "#" then return utilsMarkup.numberList(items) elseif type == "inline" and delim then return table.concat(items, mw.getCurrentFrame:preprocess(delim)) else return mw.text.listToText(items) end end

function p.termList(game, pages, options) local terms = {} local rawTerms = {} for i, page in ipairs(pages) do		local pageEnd = string.find(page, "<") local additionalInfo = "" if pageEnd then additionalInfo = string.sub(page, pageEnd, #page) page = string.sub(page, 1, pageEnd - 1) if utilsString.endsWith(page, " ") then page = utilsString.trim(page) additionalInfo = " "..additionalInfo end end terms[i] = Term.printTerm(page, game, options)..additionalInfo rawTerms[i] = Term.fetchTerm(page, game, options) or page end

return terms, rawTerms end

p.Templates = { List = { purpose = "This outputs bits of text in lists of various formats. This should be used instead  tag to make lists, so that the output HTML is semantically meaningful to screen readers (i.e. easier for the visually impaired to navigate).", format = "inline", paramOrder = {"type", "delim", "..."}, params = { type = { type = "string", nilIfEmpty = true, enum = {"*", "#", "inline"}, canOmit = true, 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", canOmit = true, 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.", trim = true, nilIfEmpty = true, },		},		examples = { {"Link", "Zelda", "Ganon"}, { type = "*", "Link", "Zelda", "Ganon"}, { type = "#", "Link", "Zelda", "Ganon"}, { 				desc = "Inline lists.", args = { type = "inline", "Link", "Zelda", "Ganon"}, },			{ type = "inline", "Link", "Zelda"}, { type = "inline", "Link"}, { type = "inline", delim = "·", "Link", "Zelda", "Ganon"}, {				desc = "This template ignores empty arguments.", args = { type = "inline", "", "Zelda", "Ganon"}, },			{ type = "inline" }, { type = "*" }, {				desc = "This template ignores surrounding whitespace on parameters. If you desire whitespace in, use Template:Space.", args = { type = "inline", delim = "; ", " Link ", " Zelda ", " Ganon "}, },			{ type = "inline", delim = ";", "Link", "Zelda", "Ganon"}, },	}, }

function p.Documentation return { termList = { params = {"game", "pages", "options"}, returns = { "A list the same size as  with Module:Term applied to each page.", "A list the same size as  with Module:Term applied to each page. The page name is returned as-is if it stores no terms.", },			cases = { {					desc = "Link's relatives", args = {"TWWHD", {"Link's Grandma", "Aryll (little sister) "}, { link = true }}, expect = { {							"Grandma", "Aryll (little sister) ", },						{"Grandma", "Aryll"}, },				},			}		}	} end

return p