Module:Outdent: Difference between revisions

Content deleted Content added
No edit summary
update per style guide (TPER)
 
(23 intermediate revisions by 5 users not shown)
Line 1:
local p = {}
local getArgs = require('Module:Arguments').getArgs
 
function p.outdent (frame)
local args = getArgs (frame)
local countwidth = 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
local reversed = 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]
forwidth = symbolwidth in+ select(2, string.gmatchgsub(args[1], ':' ,'')) -- orincrease by string.gmatch(args[1], '*'for )every do:
width = width + select(2, string.gsub(args[1],'*','')) -- increase by 1 for every *
count = count+1 -- increase count for every : or *
width = width + select(2, string.gsub(args[1],'#','')) * 2 -- increase by 2 for every #
end
if countwidth == 0 then width = tonumber(args[1]) end -- set width to args[1] to count if needed
 
count = tonumber(args[1])
if not width then width = 10 end -- default width
if width < 0
then
width = -width
reversed = not reversed
end
if width > 40 then width = 40 end -- max width
width = width * 1.6 -- set width to proper width
if not count then
count = 10 -- 10 default
end
local top = '<span style="display:block;width:' .. width .. 'em;height:0.5em;' .. (width == 0 and '' or 'border-bottom:1px solid #a2a9b1;') .. 'border-' .. ((width == 0 or reversed) and 'left' or 'right') ..':1px solid #a2a9b1;"></span>' -- top half
if count > 40 then
local bottom = '<span style="display:block;width:' .. width .. 'em;height:0.5em;border-' .. (reversed and 'right' or 'left') .. ':1px solid #a2a9b1;"></span>' -- bottom half
count = 40 -- 40 max
local note:wikitext( = args[2] and '<span>([[Wikipedia:Indentation#Outdenting|outdent]])&#32;</span>' or '') -- add (outdent) if needednote
end
count = count * 1.6 -- 0.8 -- convert to width
while i < count do -- create line
line = line..'───'
i = i+1
end
if args['test_line_width'] then -- used to test line width before and after width reduction
return line..'<br />'..'<span style="display:inline-block; overflow:hidden; word-wrap:normal; width:'..count..'em;">'..line..'</span>'
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
return '<div class="outdent-template" style="position:relative;left:1px;">' .. top .. bottom .. note .. '</div>';
end