The editors' meeting has been canceled for technical reasons.

Module:Tabs:修订间差异

来自NeuroWiki
跳转到导航 跳转到搜索
创建页面,内容为“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 tab…”
 
无编辑摘要
第37行: 第37行:
         local tab = args['tab'..i] or ''
         local tab = args['tab'..i] or ''
          
          
         -- 构建标题
         -- 构建标题(移除nowiki处理)
         local title = bticon .. bt
         local title = bticon .. bt
         if i == default then
         if i == default then
             title = title .. '@selected'
             title = title .. '@selected'
         end
         end
       
        -- 处理特殊字符
        title = mw.text.nowiki(title)
        tab = mw.text.nowiki(tab)
          
          
         table.insert(tabberContent, '|-| '..title..' = '..tab)
         table.insert(tabberContent, '|-| '..title..' = '..tab)
     end
     end
      
      
     return '<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>'
     -- 使用preprocess解析标签
    local content = '<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>'
    return mw.getCurrentFrame():preprocess(content)
end
end


return p
return p

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