模块:PageLink:修订间差异
来自「荏苒之境」
创建页面,内容为“local csv = require("Module:Csv") local page_link = {} local function format(page, text) local t = {""} if text ~= nil then t[#t+1] = text t[#t+1] = "" return table.concat(t) end local section_pos = string.find(page, "#") if section_pos then t[#t+1] = string.sub(page, 1, section_pos - 1) t[#t+1] = " § " t[#t+1] = string.sub(page, section_pos + 1, #page) t[#t+1] = "]]" else t[#t+1] = page.."]]" end return table.conca…” |
无编辑摘要 |
||
第30行: | 第30行: | ||
local entry = csv.parse_row(v, nil, "multiline") | local entry = csv.parse_row(v, nil, "multiline") | ||
local page = entry[1] | local page = entry[1] | ||
local text = entry[2] | local text = entry[2] | ||
t[#t+1] = format(page, text) | t[#t+1] = format(page, text) | ||
t[#t+1] = divider | t[#t+1] = divider |
2025年8月30日 (六) 09:36的最新版本
此模块的文档可以在模块:PageLink/doc创建
local csv = require("Module:Csv")
local page_link = {}
local function format(page, text)
local t = {"[[", page, "|"}
if text ~= nil then
t[#t+1] = text
t[#t+1] = "]]"
return table.concat(t)
end
local section_pos = string.find(page, "#")
if section_pos then
t[#t+1] = string.sub(page, 1, section_pos - 1)
t[#t+1] = " § "
t[#t+1] = string.sub(page, section_pos + 1, #page)
t[#t+1] = "]]"
else
t[#t+1] = page.."]]"
end
return table.concat(t)
end
local function format_list(entries, divider, last_divider)
last_divider = last_divider or divider
local t = {}
for i, v in ipairs(entries) do
local entry = csv.parse_row(v, nil, "multiline")
local page = entry[1]
local text = entry[2]
t[#t+1] = format(page, text)
t[#t+1] = divider
end
if #t > 2 then
t[#t-2] = last_divider
end
t[#t] = nil
return table.concat(t)
end
page_link.format = format
page_link.format_list = format_list
page_link.show_list = function(frame)
local args = frame.args
local divider = args.divider
local last_divider = args.last_divider
if last_divider == nil or last_divider == "" then
last_divider = divider
end
return format_list(frame:getParent().args, divider, last_divider)
end
return page_link