文档图示 模块文档[创建]
-- Module:Pages/sandbox
local p = {}

-- Helper function to parse ranges (like "2-5,9") into a table of pages
local function parseRange(rangeStr)
    -- (existing code for range parsing)
end

function p.pages(frame)
    local args = frame.args
    local index = args.index
    local from = tonumber(args.from) or 1
    local to = tonumber(args.to) or from
    local step = tonumber(args.step) or 1
    local excludePages = args.exclude and parseRange(args.exclude) or {}
    local includePages = args.include and parseRange(args.include) or nil
    local onlySection = args.onlysection
    local fromSection = args.fromsection
    local toSection = args.tosection

    local function transcludePage(page, section)
        local pageLink = index .. "/" .. page
        if section then
            pageLink = pageLink .. "#" .. section
        elseif onlySection then
            pageLink = pageLink .. "#" .. onlySection
        end
        return string.format("Page %s (link: %s)", page, pageLink)
    end

    local result = {}
    for i = from, to, step do
        if not excludePages[i] and (not includePages or includePages[i]) then
            local section = (i == from and fromSection) or (i == to and toSection) or nil
            table.insert(result, transcludePage(i, section))
        end
    end

    return table.concat(result, " ")
end

return p