词条 | Module:Outdent/sandbox |
释义 | 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 = ' ') -- start:wikitext(style..'width:'..count..'em;">'..line..'') -- middle :wikitext(style..'">'..End..'') -- end end
if args['test_line_width'] then -- used to test line width before and after width reduction local test_line = { 'Before:'..' 'After:'..' style..'width:'..count..'em;">', line..''..' 'Final:'..' } return table.concat (test_line) elseif args[2] then -- add (outdent) if needed local outdent_notice = { tostring(outside), '(outdent) ', } return table.concat (outdent_notice) else -- return normal line return outside end
end return p |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。