Jump to content

Module:Outdent

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 19:06, 6 October 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {} 
local getArgs = require('Module:Arguments').getArgs

function p.outdent (frame) 
	local args = getArgs (frame)
	local count = 0
	local Start = '┌'
	local End = '┘'
	local i = 0
	local line = ''
	local outside = mw.html.create('span')
	local indentTable = {'reverse','indent','in','r'}                           -- lsit of parameters that mean reverse/indent
	
	for k,v in pairs(indentTable) do                                            -- set start and end if reversed
		if args[v] then
			Start = '└'
			End = '┐'
		end
	end
	
	if not args[1] then                                                         -- set to 10 by default
		args[1] = 10
	end
	
	for symbol in string.gmatch(args[1], ':' ) or string.gmatch(args[1], '*' ) do
		count = count+1                                                         -- increase count for every : or *
	end
	
	if not tonumber(args[1]) then                                               -- set args[1] to count if needed
		args[1] = count
	end
	
	if tonumber(args[1]) > 40 then
		args[1] = 40                                                            -- 40 max
	end
	
	if tonumber(args[1]) then
		count = args[1] * 1.6                                                   -- multiply by 1.6
	else
		count = 10 *1.6                                                         -- if count isn't a number
	end
	
	count = count - 0.8                                                         -- minus 0.8
	
	while i < count*3 do                                                        -- create line
		line = line..'───'
		i = i+1
	end
	
	outside                                                                     -- create span tag
		:addClass('outdent-template')
		:css('display','block')
		:css('margin-top','-0.5em')
		:css('color','#AAA;')
		:wikitext('<span style="display:inline-block; overflow:hidden;">'..Start..'</span>') -- start
		:wikitext('<span style="display:inline-block; overflow:hidden; word-wrap:normal; width:'..count..'em;">'..line..'</span>') -- middle
		:wikitext('<span style="display:inline-block; overflow:hidden;">'..End..'</span>') -- end
	
	if args[2] then
		local note = mw.html.create('span')
		note:wikitext('([[Wikipedia:Indentation#Outdenting|outdent]])&#32;') -- add (outdent) if needed
		return tostring(outside)..tostring(note)
	else
		return outside
	end
	
end

return p