Module:NSLink

From MS-Heritage
Revision as of 02:01, 20 August 2026 by Zora3054 (talk | contribs) (Created page with "local p = {} function p.main(frame) local args = frame.args local flagStr = args[1] or "" local ns = args[2] or "" local page = args[3] or "" local display = args[4] or...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:NSLink/doc

local p = {}

function p.main(frame)
	local args = frame.args
	local flagStr = args[1] or ""
	local ns = args[2] or ""
	local page = args[3] or ""
	local display = args[4] or ""

	local linkTarget = ns .. ":" .. page
	local linkWikitext
	if display ~= "" then
		linkWikitext = string.format("[[%s|%s]]", linkTarget, display)
	else
		linkWikitext = string.format("[[%s|%s]]", linkTarget, page)
	end

	local openTags = ""
	local closeTags = ""
	for i = 1, #flagStr do
		local c = flagStr:sub(i,i)
		if c == "b" then
			openTags = openTags .. "<b>"
			closeTags = "</b>" .. closeTags
		elseif c == "i" then
			openTags = openTags .. "<i>"
			closeTags = "</i>" .. closeTags
		elseif c == "s" then
			openTags = openTags .. "<s>"
			closeTags = "</s>" .. closeTags
		elseif c == "u" then
			openTags = openTags .. "<u>"
			closeTags = "</u>" .. closeTags
		end
	end

	local output = openTags .. linkWikitext .. closeTags
	return output
end

return p