Module:Link:修订间差异

来自Arcaea中文维基
无编辑摘要
无编辑摘要
第1行: 第1行:
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}


function p.titular(frame)
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
 
p.titular = makeInvokeFunc('_titular')
 
function p._titular(args)
local result=""
local result=""
args=mw.getCurrentFrame():getParent().args
for i,k in ipairs(args) do
for i,k in ipairs(args) do
result=result..'<span id="'..k..'"></span>'
result=result..'<span id="'..k..'"></span>'
第15行: 第24行:
end
end


function p.link(frame)
p.link = makeInvokeFunc('_link')
local page,text=mw.getCurrentFrame():getParent().args[1],mw.getCurrentFrame():getParent().args[2]
 
function p._link(args)
local page,text=args[1],args[2]
local a,b,c
local a,b,c

2021年5月22日 (六) 16:27的版本

可在Module:Link/doc创建此模块的帮助文档

local getArgs = require('Module:Arguments').getArgs
local p = {}

local function makeInvokeFunc(funcName)
	return function (frame)
		local args = getArgs(frame)
		return p[funcName](args)
	end
end

p.titular = makeInvokeFunc('_titular')

function p._titular(args)
	local result=""
	for i,k in ipairs(args) do
		result=result..'<span id="'..k..'"></span>'
	end
	return result
end

function link(page,name)
	local result= '[['..page..'列表#'..name..'|'..name..']]'
	return result
end

p.link = makeInvokeFunc('_link')

function p._link(args)
	local page,text=args[1],args[2]
	local a,b,c
	
	a,b = text:match('([^\s]*) (feat.*)') 
	if a and b then
		return link(page,a)..' '..b
	end
	
	a,b,c = text:match('([^\s]*) (vs) ([^\s]*)') 
	if a and b and c then
		return link(page,a)..' '..b..' '..link(page,c)
	end
	
	a,b,c = text:match('([^\s]*) (×) ([^\s]*)') 
	if a and b and c then
		return link(page,a)..' '..b..' '..link(page,c)
	end

	a,b,c = text:match('([^\s]*) (vs.) ([^\s]*)') 
	if a and b and c then
		return link(page,a)..' '..b..' '..link(page,c)
	end

	return link(page,text)
end

return p