Module:Pages/sandbox
外观
这是Module:Pages(差异)的沙盒。 参见本模块的测试样例(运行)。 |
模块文档[创建]
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (编辑 | 差异)和测试样例 (编辑 | 运行)页面进行实验。 请在/doc子页面中添加分类。 本模块的子页面。 |
-- 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