Module:Sandbox/Nardog/7

Revision as of 11:31, 4 August 2020 by imported>Nardog
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Sandbox/Nardog/7/doc

local p = {}

function p.main(args)
	local segments = mw.loadData('Module:Sandbox/Nardog/6').segments
	local ret = {}
	local underlined, hasError
	local function endUnderline()
		if underlined then
			table.insert(ret, '</span>')
			underlined = false
		end
	end
	for i, v in ipairs(args) do
		local t = segments[v]
		if t then
			if t.tooltip then
				if not underlined then
					table.insert(ret, '<span class="IPAc-en-tooltip">')
					underlined = true
				end
				table.insert(ret, string.format(
					'<span title="%s" class="rt-commentedText">%s</span>',
					t.tooltip, t.text))
			else
				endUnderline()
				table.insert(ret, t.text)
			end
		else
			endUnderline()
			table.insert(ret, string.format(
				'<span class="error">[invalid input: \'%s\']</span>',
				mw.text.nowiki(v)))
			hasError = true
		end
	end
	endUnderline()
	return table.concat(ret), hasError
end

return p