Jump to content

Module:Sandbox

From translatewiki.net

local p={}
function p.test(f) local a=f.args[1] 
	function c(t) return '<code style=color:red;font-weight:bold;background:lime;border-color:blue;border-radius:.4em>the '..t..'</code>' end
	if not a then return c('parameter is unspecified')
	elseif a=='' then return c('parameter is empty')
	else return c('specified parameter is “'..a..'”') end
end
function p.tl(f)
	local a=f.args
	function nw(t) return f:extensionTag('nowiki',t) end
	if a.tag=='' or not a.tag then tag='code' else tag=a.tag end
	if a.template=='' or not a.template then n=a[1] else n=a.template end
	if f:callParserFunction('ucfirst',n)==mw.title.new(n).text then link='Template:'..n else link=n end
	if a.shl=='1' then color=' style=color:#80c';b='<b>';bb='</b>';
		function u(t) return '<u'..color..'>'..nw(t)..'</u>' end
		function eb(t) if t~='' then m='([^{}]-)';r='%1'
			function gsub(t) return t:gsub(m..'(&#[Xx]3[Dd];).*',r):gsub(m..'(&#61;).*',r):gsub(m..'(&equals;).*',r):gsub(m..'({{=}}).*',r):gsub(m..'(=).*',r) end
			if t==gsub(t) then t=bb..nw(t)..b else r='%1%2'
				function sub(t) return mw.ustring.sub(t,1+mw.ustring.len(gsub(t))) end
				if sub(t)=='' then t=nw(t) else t=nw(gsub(t))..bb..nw(sub(t))..b end
			end 
		end return t end
	else color='';b='';bb='';
		function u(t) return nw(t) end
		function eb(t) return nw(t) end
	end
	local r='<'..tag..color..'>'..b..'{{[['..link..'|'..u(n)..']]'
	for i,v in ipairs(a) do 
		if a.template or i>1 then r=r..'|'..eb(v) end 
	end
	r=r..'}}'..bb..'</'..tag..'>'
	return r
end
return p