Module:Tabs:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
(未显示同一用户的2个中间版本) | |||
第3行: | 第3行: | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local indices = {} | local indices = {} | ||
-- | -- 收集有效标签索引 | ||
for k, _ in pairs(args) do | for k, _ in pairs(args) do | ||
local num = k:match('^bt(%d+)$') or k:match('^tab(%d+)$') | local num = k:match('^bt(%d+)$') or k:match('^tab(%d+)$') | ||
if num then | if num then indices[tonumber(num)] = true end | ||
end | end | ||
-- | -- 处理标签排序 | ||
local sorted = {} | local sorted = {} | ||
for k in pairs(indices) do | for k in pairs(indices) do table.insert(sorted, k) end | ||
table.sort(sorted) | table.sort(sorted) | ||
-- | -- 确定默认标签位置(基于参数顺序) | ||
local | local default_pos = math.min(tonumber(args.DefaultTab) or 1, #sorted) | ||
-- 构建标签内容 | -- 构建标签内容 | ||
local tabberContent = {} | local tabberContent = {} | ||
for | for pos, idx in ipairs(sorted) do | ||
local | local title = args['bt'..idx] or '' | ||
local content = args['tab'..idx] or '' | |||
local | |||
table.insert(tabberContent, '|-| ' | table.insert(tabberContent, string.format('|-| %s=%s', title, content)) | ||
end | end | ||
return mw.getCurrentFrame():preprocess( | |||
'<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>' | |||
) | |||
end | end | ||
-- 添加数学函数兼容 | |||
math.min = math.min or function(a, b) return a < b and a or b end | |||
return p | return p |