The editors' meeting has been canceled for technical reasons.
Module:Tabs:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
小无编辑摘要 |
||
第16行: | 第16行: | ||
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 title = args['bt'..idx] or '' | local title = args['bt'..idx] or '' | ||
local content = args['tab'..idx] or '' | local content = args['tab'..idx] or '' | ||
table.insert(tabberContent, string.format('|-| %s = %s', title, content)) | -- 添加@selected标记(修正空格问题) | ||
if pos == default_pos then | |||
title = title .. ' @selected' | |||
end | |||
table.insert(tabberContent, string.format('|-| %s=%s', title, content)) | |||
end | end | ||
第34行: | 第38行: | ||
end | end | ||
-- | -- 添加数学函数兼容 | ||
math. | math.min = math.min or function(a, b) return a < b and a or b end | ||
end | |||
return p | return p |
2025年3月1日 (六) 23:16的版本
此模块的文档可以在Module:Tabs/doc创建
local p = {}
function p.main(frame)
local args = frame:getParent().args
local indices = {}
-- 收集有效标签索引
for k, _ in pairs(args) do
local num = k:match('^bt(%d+)$') or k:match('^tab(%d+)$')
if num then indices[tonumber(num)] = true end
end
-- 处理标签排序
local sorted = {}
for k in pairs(indices) do table.insert(sorted, k) end
table.sort(sorted)
-- 确定默认标签位置(基于参数顺序)
local default_pos = math.min(tonumber(args.DefaultTab) or 1, #sorted)
-- 构建标签内容
local tabberContent = {}
for pos, idx in ipairs(sorted) do
local title = args['bt'..idx] or ''
local content = args['tab'..idx] or ''
-- 添加@selected标记(修正空格问题)
if pos == default_pos then
title = title .. ' @selected'
end
table.insert(tabberContent, string.format('|-| %s=%s', title, content))
end
return mw.getCurrentFrame():preprocess(
'<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>'
)
end
-- 添加数学函数兼容
math.min = math.min or function(a, b) return a < b and a or b end
return p