The editors' meeting has been canceled for technical reasons.

Module:Tabs

来自NeuroWiki
Selfice留言 | 贡献2025年3月1日 (六) 22:23的版本
跳转到导航 跳转到搜索

此模块的文档可以在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 = math.clamp(tonumber(args.DefaultTab) or 1, 1, #sorted)
    
    -- 构建标签内容
    local tabberContent = {}
    for i, idx in ipairs(sorted) do
        local title = args['bt'..idx] or ''
        if i == default then title = title .. '@selected' end
        local content = args['tab'..idx] or ''
        
        table.insert(tabberContent, string.format('|-| %s = %s', title, content))
    end
    
    return mw.getCurrentFrame():preprocess(
        '<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>'
    )
end

-- 添加数学钳制函数兼容
math.clamp = math.clamp or function(val, min, max)
    return math.min(math.max(val, min), max)
end

return p