FANDOM


--[[----------------------------------------------------------------------------
	Module:T
		For documentation, see Template:T
----------------------------------------------------------------------------]]--
 
local p = {}
 
local yesno = require('Module:Yesno')
local f = string.format -- Efficiency
 
local function wrap(str)
	if str == '' then return str end -- Don't wrap empty string
	return tostring(mw.html.create('span')
		:css('color', 'gray')
		:wikitext(f("''<%s>''", tostring(str))))
end
 
function p.main(frame)
	local args = frame:getParent().args
	local template = args[1] or ''
	if template == '' then error('T: Must specify a template') end
	local ml = yesno(args.multiline) or false
	local sep = ml and '\n|' or '|'
	local params = {}
	for k, v in ipairs(args) do -- Loop through args
		if k ~= 1 then
			if string.match(v, '%[.+%].*') then --Named param
				local pkey, pval = string.match(v, '%[(.+)%]%s?(.*)')
				table.insert(params, f('%s=%s', pkey, wrap(pval)))
			else --Unnamed param
				table.insert(params, wrap(v))
			end
		end
	end
 
	local css = ml and {['white-space'] = 'pre-wrap', display = 'block'} or ''
	return mw.html.create('code')
		:css(css)
		:wikitext(f('%s[[Template:%s|%s]]%s%s%s%s',
			mw.text.nowiki('{{'),
			template, template,
			#params > 0 and sep or '',
			table.concat(params, sep),
			ml and '\n' or '',
			mw.text.nowiki('}}')))
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.