Module:Outdent/sandbox
Appearance
![]() | This is the module sandbox page for Module:Outdent (diff). |
Implements {{Outdent}}.
See also
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 _,v in pairs(indentTable) do -- set start and end if reversed
if args[v] then
Start = '└'
End = '┐'
end
end
args[1] = args[1] or '' -- un-nil args[1]
for _ in string.gmatch(args[1],'[:*]') do
count = count+1 -- increase count by 1 for every : or *
end
for _ in string.gmatch(args[1],'#') do
count = count+2 -- increase count by 2 for every #
end
if count == 0 then -- set count to args[1] if needed
count = tonumber(args[1])
end
if not count then
count = 10 -- 10 default
end
count = count * 1.6 - 0.7 -- convert to width
local lineMath = math.ceil(count * 1.6)
while i < lineMath do -- create line
line = line..'─'
i = i+1
end
local style = '<span style="display:inline-block; overflow:hidden;'
outside -- add outside style and class
:addClass('outdent-template')
:css('display','block')
:css('margin-top','-0.5em')
:css('color','#AAA')
:css('word-wrap','normal')
if count == -0.7 then -- if was 0
outside
:css('margin-top','0.25em')
:wikitext('|')
else -- if count wasn't 0
outside
:css('position','relative')
:css('left','-0.25em')
:css('margin-top','-0.25em')
:wikitext(style..'">'..Start..'</span>') -- start
:wikitext(style..'width:'..count..'em;">'..line..'</span>') -- middle
:wikitext(style..'">'..End..'</span>') -- end
end
if args['test_line_width'] then -- used to test line width before and after width reduction
local test_line = {
'Before:'..'<br />'..line..'<br />',
'After:'..'<br />',
style..'width:'..count..'em;">',
line..'</span>'..'<br />',
'Final:'..'<br />'..tostring(outside),
}
return table.concat (test_line)
elseif args[2] then -- add (outdent) if needed
local outdent_notice = {
tostring(outside),
'([[Wikipedia:Indentation#Outdenting|outdent]]) ',
}
return table.concat (outdent_notice)
else -- return normal line
return outside
end
end
return p