local p = {}
local getArgs = require('Module:Arguments').getArgs
function p._main(args)
-- 初始化单元格颜色
local cells = {}
for i = 1, 9 do
cells[i] = '6b6b6b'
end
-- 处理数字参数(顺序参数)
local firstValue
for i, value in ipairs(args) do
local num = tonumber(value)
if num and num >= 1 and num <= 9 then
if i == 1 then
cells[num] = 'f0f0f0'
firstValue = value
else
if value ~= firstValue then
cells[num] = '00fedc'
end
end
end
end
-- 处理命名参数(颜色覆盖)
for key, color in pairs(args) do
if type(key) == 'string' then
local num = tonumber(key:match('^color(%d)$'))
if num and num >= 1 and num <= 9 then
cells[num] = color:gsub('#', '')
end
end
end
-- 获取宽度参数
local width = args.width or '20'
-- 生成HTML表格
local html = {
'<TABLE border="2" cellpadding="1" style="border-collapse:separate;border-spacing:1px;margin:0 auto">',
string.format('<TR><TD BGCOLOR="#%s" height="%s" width="%s"> <TD BGCOLOR="#%s" height="%s" width="%s"> <TD BGCOLOR="#%s" height="%s" width="%s"></TR>',
cells[7], width, width, cells[8], width, width, cells[9], width, width),
string.format('<TR><TD BGCOLOR="#%s" height="%s" width="%s"><TD BGCOLOR="#%s" height="%s" width="%s"><TD BGCOLOR="#%s" height="%s" width="%s"></TR>',
cells[4], width, width, cells[5], width, width, cells[6], width, width),
string.format('<TR><TD BGCOLOR="#%s" height="%s" width="%s"><TD BGCOLOR="#%s" height="%s" width="%s"><TD BGCOLOR="#%s" height="%s" width="%s"></TR>',
cells[1], width, width, cells[2], width, width, cells[3], width, width),
'</TABLE>'
}
return table.concat(html)
end
function p.main(frame)
local args = getArgs(frame, {
parentFirst = true,
})
return p._main(args)
end
return p