Module:Outdent: Difference between revisions
Appearance
Content deleted Content added
BrandonXLF (talk | contribs) Undid revision 863011337 by BrandonXLF (talk) |
BrandonXLF (talk | contribs) Fixed error with pipes and added support for # |
||
Line 21: | Line 21: | ||
if not args[1] then args[1] = '' end -- un-nil args[1] |
if not args[1] then args[1] = '' end -- un-nil args[1] |
||
for |
for _ in string.gmatch(args[1],':') do |
||
count = count+1 -- increase count for every : |
count = count+1 -- increase count for every : |
||
end |
end |
||
for |
for _ in string.gmatch(args[1],'*') do |
||
count = count+1 -- increase count for every * |
count = count+1 -- increase count for every * |
||
end |
|||
for _ in string.gmatch(args[1],'#') do |
|||
count = count+2 -- increase count by 2 for every # |
|||
end |
end |
||
Line 69: | Line 73: | ||
: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; word-wrap:normal; width:'..count..'em;">'..line..'</span>') -- middle |
||
:wikitext('<span style="display:inline-block; overflow:hidden;">'..End..'</span>') -- end |
:wikitext('<span style="display:inline-block; overflow:hidden;">'..End..'</span>') -- end |
||
if line ~= |
if line ~= '|' then -- if not pipe (|) |
||
outside |
outside |
||
:css('position','relative') |
:css('position','relative') |
||
:css('left','-0.25em') |
:css('left','-0.25em') |
||
else |
|||
outside |
|||
:css('margin-top','0.25em') |
|||
end |
end |
||
if args[2] then |
if args[2] then |
Revision as of 04:02, 8 October 2018
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 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 args[1] = '' end -- un-nil args[1]
for _ in string.gmatch(args[1],':') do
count = count+1 -- increase count for every :
end
for _ in string.gmatch(args[1],'*') do
count = count+1 -- increase count for every *
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
if count > 40 then
count = 40 -- 40 max
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
if count == - 0.7 then -- set to pipe | if count was 0
line = '|'
Start = ''
End = ''
end
if args['test_line_width'] then -- used to test line width before and after width reduction
return 'Before:'..line..'<br />'..'<span style="display:inline-block; overflow:hidden; word-wrap:normal; width:'..count..'em;">'..'After:'..line..'</span>'
end
outside -- create span tag
:addClass('outdent-template')
:css('display','block')
:css('margin-top','-0.5em')
:css('color','#AAA;') -- account for the fact that ┐ and related have empty space
: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 line ~= '|' then -- if not pipe (|)
outside
:css('position','relative')
:css('left','-0.25em')
else
outside
:css('margin-top','0.25em')
end
if args[2] then
local note = mw.html.create('span')
note:wikitext('([[Wikipedia:Indentation#Outdenting|outdent]]) ') -- add (outdent) if needed
return tostring(outside)..tostring(note)
else
return outside
end
end
return p