Module:Outdent: Difference between revisions
Jump to navigation
Jump to search
Richardpruen (talk | contribs) m 1 revision imported |
Richardpruen (talk | contribs) m 1 revision imported |
||
(One intermediate revision by one other user not shown) | |||
Line 6: | Line 6: | ||
local width = 0 | local width = 0 | ||
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] | if not args[1] then args[1] = '' end -- un-nil args[1] | ||
Line 14: | Line 14: | ||
if width == 0 then width = tonumber(args[1]) end -- set width to args[1] if needed | 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 not width then width = 10 end -- default width | ||
if width < 0 | if width < 0 | ||
then | then | ||
width = -width | width = -width | ||
reversed = not reversed | |||
end | end | ||
if width > 40 then width = 40 end -- max width | if width > 40 then width = 40 end -- max width | ||
Line 25: | Line 25: | ||
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:1px solid # | 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 | ||
local bottom = '<span style="display:block;width:' .. width .. 'em;height:0.5em;border-' .. ( | local bottom = '<span style="display:block;width:' .. width .. 'em;height:0.5em;border-' .. (reversed and 'right' or 'left') .. ':1px solid #a2a9b1;"></span>' -- bottom half | ||
local note = args[2] and '<span>([[Wikipedia:Indentation#Outdenting|outdent]]) </span>' or '' -- note | local note = args[2] and '<span>([[Wikipedia:Indentation#Outdenting|outdent]]) </span>' or '' -- note | ||
Latest revision as of 16:11, 5 December 2021
Documentation for this module may be created at Module:Outdent/doc
Script error: Lua error: Internal error: The interpreter exited with status 127.
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.outdent (frame)
local args = getArgs(frame)
local width = 0
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]
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 < 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
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
local bottom = '<span style="display:block;width:' .. width .. 'em;height:0.5em;border-' .. (reversed and 'right' or 'left') .. ':1px solid #a2a9b1;"></span>' -- bottom half
local note = args[2] and '<span>([[Wikipedia:Indentation#Outdenting|outdent]]) </span>' or '' -- note
return '<div class="outdent-template" style="position:relative;left:1px;">' .. top .. bottom .. note .. '</div>';
end
return p