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)
			local e='';for _,eq in ipairs(p) do
				if t:find(eq) then
					local beq,aeq=t:match('(.-)'..eq..'(.*)');if aeq~=e then aeq=bb..nw(aeq)..b end;e=nil;t=nw(beq)..eq..aeq
				end
			end
			if e and t ~= e then t=bb..nw(t)..b 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