Module:Main

local p = {}

local Constants = mw.loadData("Module:Constants/Data")

local utilsArg = require("Module:UtilsArg") local utilsError = require("Module:UtilsError") 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.Main) local categories = err and err.categoryText or "" if args._pages then return frame:expandTemplate({			title = "Main/Old",			args = utilsTable.concat(args.pages, args._pages),		}) .. categories .. "\n" end if args.pages == nil or #args.pages == 0 then return "", categories end local pages = utilsTable.map(args.pages or {}, p.formatListItem) pages = utilsTable.compact(pages) -- remove nils if #args.pages ~= #pages then utilsError.warn(string.format("Page list cannot have blank entries: ", frame:getParent.args[1])) categories = categories..string.format("", Constants.category.invalidArgs) end

local text = #pages > 1 and "Main articles: " or "Main article: " local pageList = text..mw.text.listToText(pages) local html = mw.html.create("div") :addClass(Constants.class.hatnote) :wikitext(pageList)

return tostring(html), categories end

function p.formatListItem(item) item = mw.text.decode(item) if utilsString.isBlank(item) then return nil elseif utilsMarkup.containsLink(item) then return item elseif string.find(item, "#") then local linkDisplay = string.gsub(item, "#", " § ") return string.format("%s", item, linkDisplay) else return string.format("%s", item) end end

p.Templates = { ["Main"] = { purpose = "To be placed under a heading when that section's topic has its own page or pages.", categories = {"Formatting Templates"}, params = { [1] = {				name = "pages", required = true, desc = "Comma separated list of wiki page names.", trim = true, nilIfEmpty = true, split = true, },			["..."] = {				name = "_pages", deprecated = true, },		},		examples = { {"Blue Bubble"}, {"Blue Bubble, Green Bubble, Red Bubble"}, {				desc = "Use when an article name contains commas.", args = {"The Way of Sumo, Part I, The Way of Sumo, Part 2, The Way of Sumo, Part 3"}, },			{				desc = "Section links are supported but generally discouraged.", args = {"Zora Shop#Majora's Mask"}, },			{				desc = "Custom link displays are supported but generally discouraged. Links to redirects are preferable.", args = {"Thief in the Night, Thief in the Night"}, },			{				desc = "Former template format - now deprecated.", args = {"Spear Moblin", "A", "Bow Moblin", "", "Shield Moblin", "C"}, },			{				desc = "Blank entries are not allowed", args = {"Blue Bubble,, Red Bubble, "}, },			{				desc = "At least one page must be specified.", args = {""}, },			{},			}	} }

return p