The editors' meeting has been canceled for technical reasons.

Module:Tabs:修订间差异

来自NeuroWiki
跳转到导航 跳转到搜索
无编辑摘要
无编辑摘要
第3行: 第3行:
function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
    local tabs = {}
     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
            num = tonumber(num)
            indices[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.insert(sorted, k)
    end
     table.sort(sorted)
     table.sort(sorted)
      
      
     -- 处理默认标签
     -- 确定默认标签
     local default = tonumber(args.DefaultTab) or 1
     local default = math.clamp(tonumber(args.DefaultTab) or 1, 1, #sorted)
    if default < 1 or default > #sorted then
        default = 1
    else
        default = sorted[default]  -- 修正为实际存在的标签索引
    end
      
      
     -- 构建标签内容
     -- 构建标签内容
     local tabberContent = {}
     local tabberContent = {}
     for _, i in ipairs(sorted) do
     for i, idx in ipairs(sorted) do
         local bt = args['bt'..i] or ''
         local title = args['bt'..idx] or ''
         local bticon = args['bticon'..i] or ''
         if i == default then title = title .. '@selected' end
         local tab = args['tab'..i] or ''
         local content = args['tab'..idx] or ''
       
        -- 构建标题(移除nowiki处理)
        local title = bticon .. bt
        if i == default then
            title = title .. '@selected'
        end
          
          
         table.insert(tabberContent, '|-| '..title..' = '..tab)
         table.insert(tabberContent, string.format('|-| %s = %s', title, content))
     end
     end
      
      
     -- 使用preprocess解析标签
     return mw.getCurrentFrame():preprocess(
    local content = '<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>'
        '<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>'
     return mw.getCurrentFrame():preprocess(content)
    )
end
 
-- 添加数学钳制函数兼容
math.clamp = math.clamp or function(val, min, max)
     return math.min(math.max(val, min), max)
end
end


return p
return p

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