Module:template: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
Line 14: Line 14:
end
end
end
end
table.insert(out, (nested and "") or "</code>", "&#125;&#125;")
table.insert(out, ((nested and "") or "</code>") .. "&#125;&#125;")
return table.concat(out)
return table.concat(out)
end
end

Revision as of 18:14, 5 August 2023

Documentation for this module may be created at Module:template/documentation

local export = {}

local function make_template(frame, nested)
	local args = (frame:getParent() and frame:getParent().args) or frame.args
	local out = {"&#123;&#123;", (nested and "<code>") or "", frame.args[1]}
	local i = 2
	while frame.args[i] do
		table.insert(out, "&#124;" .. frame.args[i])
		i = i + 1
	end
	for key, value in ipairs(frame.args) do
		if type(key) == "string" then
			table.insert(out, "&#124;" .. key .. "=" .. value)
		end
	end
	table.insert(out, ((nested and "") or "</code>") .. "&#125;&#125;")
	return table.concat(out)
end

function export.show(frame)
	return make_template(frame, false)
end

function export.showNested(frame)
	return make_template(frame, true)
end

return export