打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:SectionLinkJoin

来自卡特霍普
GTEH留言 | 贡献2025年6月13日 (五) 21:55的版本 (创建页面,内容为“local p = {} function p.main(frame) local parent = frame:getParent() local args = parent and parent.args or {} return p._joinSectionLinks(args) end function p._joinSectionLinks(args) local items = {} local maxIndex = 0 for key, value in pairs(args) do if tonumber(key) and value ~= '' then local index = tonumber(key) if index > maxIndex then maxIndex = index end end end for i = 1…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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

local p = {}

function p.main(frame)
    local parent = frame:getParent()
    local args = parent and parent.args or {}
    return p._joinSectionLinks(args)
end

function p._joinSectionLinks(args)
    local items = {}
    local maxIndex = 0
    
    for key, value in pairs(args) do
        if tonumber(key) and value ~= '' then
            local index = tonumber(key)
            if index > maxIndex then maxIndex = index end
        end
    end
    
    for i = 1, maxIndex do
        if args[i] and args[i] ~= '' then
            local displayText = args[i]
            displayText = displayText:gsub("#", " § ")
            
            local linkTarget = args['link'..i] or args[i]
            
            local link = '[[' .. linkTarget .. '|' .. displayText .. ']]'
            table.insert(items, link)
        end
    end
    
    return p._joinList(items)
end

function p._joinList(list)
    local count = #list
    
    if count == 0 then
        return ""
    elseif count == 1 then
        return list[1]
    elseif count == 2 then
        return list[1] .. "和" .. list[2]
    else
        local firstPart = table.concat(list, "、", 1, count - 1)
        return firstPart .. "和" .. list[count]
    end
end

return p