De Muysc cubun - Lengua Muisca

Revisión del 14:19 12 sep 2025 de Diegomez (discusión | contribs.) (Página creada con «local p = {} local function splitCSV(s, sep) s = s or '' sep = sep or ',' local t = {} for token in mw.text.gsplit(s, sep, true) do token = mw.text.trim(token) if…»)
(difs.) ← Revisión anterior | Revisión actual (difs.) | Revisión siguiente → (difs.)

La documentación para este módulo puede ser creada en Módulo:LinkList/doc

local p = {}

local function splitCSV(s, sep)
	s = s or ''
	sep = sep or ','
	local t = {}
	for token in mw.text.gsplit(s, sep, true) do
		token = mw.text.trim(token)
		if token ~= '' then table.insert(t, token) end
	end
	return t
end

function p.links(frame)
	local args = frame:getParent() and frame:getParent().args or frame.args
	local values = args.valores or args[1] or ''
	local outsep = args.sep or ', '
	local ns = args.ns or ''            -- Ej. "Categoría:" o "Plantilla:"
	local leadcolon = args.leadcolon or '' -- "yes" para anteponer ":" (evitar categorizar)
	local prefix = args.prefix or ''
	local suffix = args.suffix or ''
	local sort = (args.sort or '') ~= ''

	local items = splitCSV(values)
	if sort then
		table.sort(items, function(a,b) return mw.ustring.lower(a) < mw.ustring.lower(b) end)
	end

	local out = {}
	for _, it in ipairs(items) do
		local target, label = it:match('^(.-)|(.+)$')
		if not target then target, label = it, it end
		target = prefix .. target .. suffix
		local fulltarget = (leadcolon ~= '' and ':' or '') .. ns .. target
		table.insert(out, string.format('[[%s|%s]]', fulltarget, label))
	end

	return table.concat(out, outsep)
end

return p