The editors' meeting has been canceled for technical reasons.

Module:Tabs

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

此模块的文档可以在Module:Tabs/doc创建

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local tabs = {}
    local indices = {}
    
    -- 收集所有存在的标签索引
    for k, _ in pairs(args) do
        local num = k:match('^bt(%d+)$') or k:match('^tab(%d+)$')
        if num then
            num = tonumber(num)
            indices[num] = true
        end
    end
    
    -- 转换并排序索引
    local sorted = {}
    for k in pairs(indices) do
        table.insert(sorted, k)
    end
    table.sort(sorted)
    
    -- 处理默认标签
    local default = tonumber(args.DefaultTab) or 1
    if default < 1 or default > #sorted then
        default = 1
    else
        default = sorted[default]  -- 修正为实际存在的标签索引
    end
    
    -- 构建标签内容
    local tabberContent = {}
    for _, i in ipairs(sorted) do
        local bt = args['bt'..i] or ''
        local bticon = args['bticon'..i] or ''
        local tab = args['tab'..i] or ''
        
        -- 构建标题(移除nowiki处理)
        local title = bticon .. bt
        if i == default then
            title = title .. '@selected'
        end
        
        table.insert(tabberContent, '|-| '..title..' = '..tab)
    end
    
    -- 使用preprocess解析标签
    local content = '<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>'
    return mw.getCurrentFrame():preprocess(content)
end

return p