Module:Sandbox/Sameboat/m3
Appearance
local p = {}
local function pre_block(text)
-- Pre tags returned by a module do not act like wikitext <pre>...</pre>.
return '<pre>' ..
mw.text.nowiki(text) ..
(text:sub(-1) == '\n' and '' or '\n') ..
'</pre>\n'
end
function p.trimmer(frame)
-- Trims first and last empty icon cell of each row.
local org = mw.text.unstripNoWiki(frame.args[1]) or 'Paste Routemap RDT markups between the nowiki tags'
local res = org
local restable = {}
for i, v in ipairs(mw.text.split(res, '\n')) do
v = mw.text.split(v, '\\')
for _ in ipairs(v) do
if v[1] == '' and v[table.maxn(v)] == '' then
table.remove(v, 1)
table.remove(v, table.maxn(v))
end
restable.row = table.concat(v, '\\')
end
table.insert(restable, restable.row)
end
--return table.concat(restable, '\n')
return "\n'''Trimmed''':\n" .. pre_block(table.concat(restable, '\n')) .. "'''''Before trimming''''':\n" .. pre_block(org)
--return table.maxn(mw.text.split([[1\2\3\4\5]], '\\'))
--return table.concat(mw.text.split(mw.text.trim(org), '\\'), '\\')
--return table.concat(mw.text.split([[\\\STR\STR\\]], '\\'), '\\')
end
function p.trimmer2(frame)
-- Trims first and last empty icon cell of each row.
local org = mw.text.unstripNoWiki(frame.args[1]) or 'Paste Routemap RDT markups between the nowiki tags'
local res = org
local restable = {}
for i, v in ipairs(mw.text.split(res, '\n')) do
v = mw.text.split(v, '! !')
for i2, v2 in ipairs(v) do
v2 = mw.text.split(v2, '~~')
for i3, v3 in ipairs(v) do
v3 = mw.text.split(v3, '\\')
for _ in ipairs(v3) do
if v3[1] == '' and v[table.maxn(v3)] == '' then
table.remove(v3, 1)
table.remove(v3, table.maxn(v3))
end
restable.icon = table.concat(v3, '\\')
end
restable.right = {}
table.insert(restable.right, restable.icon)
restable.right2 = table.concat(restable.right, '~~')
end
restable.left = {}
table.insert(restable.left, restable.right2)
restable.left2 = table.concat(restable.left, '! !')
end
restable.row = {}
table.insert(restable.row, restable.left2)
end
return "\n'''Trimmed''':\n" .. pre_block(table.concat(restable.row, '\n')) .. "'''''Before trimming''''':\n" .. pre_block(org)
end
return p