Module:In5
Revision as of 12:15, 27 June 2013 by blackwiki>Mr. Stradivarius (fix comment)
| This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This is a Lua implementation of the {{in5}} template. Please see the template page for documentation.
-- This module implements {{in5}}.
local p = {}
function p.in5(frame)
local indent = frame.args[1] or 5 -- Default to 5.
indent = tonumber( mw.text.trim(indent) ) -- Trim whitespace and convert to number.
if not indent or indent <= 0 or math.floor(indent) ~= indent then
return -- Return blank for zero or bad input.
end
local base = ' '
local modulo = ' '
--[[
Indent values and the corresponding values for base and modulo:
indent base modulo
1 0 1
2 0 2
3 1 1
4 1 2
5 2 1
6 2 2
7 3 1
8 3 2
9 4 1
10 4 2
]]
local baseNum = math.floor( (indent - 1) / 2 )
local modNum = math.fmod( indent - 1 , 2 ) + 1
return mw.ustring.rep( base, baseNum) .. mw.ustring.rep( modulo, modNum )
end
return p