Jump to content

Module:Outdent/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Using em
Using pixels for border, using 1px instead of 2px which looks very out of place.
Line 20: Line 20:
width = width * 1.6 -- set width to proper width
width = width * 1.6 -- set width to proper width
local top = '<span style="display:block;width:' .. width .. 'em;height:0.5em;' .. (width == 0 and '' or 'border-bottom:0.1em solid #AAA;') .. 'border-' .. ((width == 0 or args['r']) and 'left' or 'right') ..':0.12em solid #BDBDBD;"></span>' -- top half
local top = '<span style="display:block;width:' .. width .. 'em;height:0.5em;' .. (width == 0 and '' or 'border-bottom:1px solid #AAA;') .. 'border-' .. ((width == 0 or args['r']) and 'left' or 'right') ..':1px solid #BDBDBD;"></span>' -- top half
local bottom = '<span style="display:block;width:' .. width .. 'em;height:0.5em;border-' .. (args['r'] and 'right' or 'left') .. ':0.12em solid #BDBDBD;"></span>' -- bottom half
local bottom = '<span style="display:block;width:' .. width .. 'em;height:0.5em;border-' .. (args['r'] and 'right' or 'left') .. ':2px solid #BDBDBD;"></span>' -- bottom half
local note = args[2] and '<span>([[Wikipedia:Indentation#Outdenting|outdent]])&#32;</span>' or '' -- note
local note = args[2] and '<span>([[Wikipedia:Indentation#Outdenting|outdent]])&#32;</span>' or '' -- note

Revision as of 01:14, 19 November 2019

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

function p.outdent (frame) 
	local args = getArgs(frame)
	local width = 0
	
	args['r'] = args['reverse'] or args['indent'] or args['r'] or args['in']	-- aliases for reverse
	if not args[1] then args[1] = '' end                                        -- un-nil args[1]
	
	width = width + select(2, string.gsub(args[1],':',''))						-- increase by 1 for every :
	width = width + select(2, string.gsub(args[1],'*',''))						-- increase by 1 for every *
	width = width + select(2, string.gsub(args[1],'#','')) * 2					-- increase by 2 for every #
	
	if width == 0 then width = tonumber(args[1]) end							-- set width to args[1] if needed
	
	if not width then width = 10 end											-- default width
	if width > 40 then width = 40 end											-- max width
	
	width = width * 1.6															-- set width to proper width
	
	local top = '<span style="display:block;width:' .. width .. 'em;height:0.5em;' .. (width == 0 and '' or 'border-bottom:1px solid #AAA;') .. 'border-' .. ((width == 0 or args['r']) and 'left' or 'right') ..':1px solid #BDBDBD;"></span>' -- top half
	local bottom = '<span style="display:block;width:' .. width .. 'em;height:0.5em;border-' .. (args['r'] and 'right' or 'left') .. ':2px solid #BDBDBD;"></span>' -- bottom half
	local note = args[2] and '<span>([[Wikipedia:Indentation#Outdenting|outdent]])&#32;</span>' or '' -- note
	
	return '<span class="outdent-template" style="position:relative;left:1px;">' .. top .. bottom .. note .. '</span>';
end

return p