模块:Linksplit
此模块的文档可以在模块:Linksplit/doc创建
local p = {}
function p.main(frame)
local wrappers = {
['Template:沙盒'] = true,
['Template:Linksplit'] = true,
}
local parent = frame:getParent()
if parent and wrappers[parent:getTitle()] then
frame = parent
end
return p._main(frame.args)
end
function p._main(args)
local titles = {} -- 链接
local _c = args.c or ':'
local sep = args.char or ' • '
local delcontent = args.del or ''
local afterdel -- 要删除的内容
-- 处理参数1~n
for _, v in ipairs(args) do
v = mw.text.trim(v)
-- 判断是否有{{!}}(已被展开)
if v ~= "" then
if not mw.ustring.find(v, "|") then
afterdel = mw.ustring.gsub(v , delcontent ,'')
if args.prefix then
table.insert(titles, args.prefix.._c..v.."|"..afterdel)
else
table.insert(titles, v.."|"..mw.ustring.gsub(afterdel,"^(.*)".._c,""))
end
else
table.insert(titles, v)
end
end
end
local str = table.concat(titles, ']]'..sep.."[[")
return '[['..str..']]'
end
return p