模块:Redirect-distinguish-for

来自决策链云智库
Zeroclanzhang讨论 | 贡献2024年1月21日 (日) 21:14的版本 (创建页面,内容为“mArguments = require('Module:Arguments') mRedirectHatnote = require("Module:Redirect hatnote") local p = {} function p.redirectDistinguishFor(frame) local args = mArguments.getArgs(frame, {parentOnly = true}) local maxArg = 0 for k, v in pairs(args) do if type(k) == 'number' and k > maxArg then maxArg = k end end local parsedArgs = {} for i = 1, maxArg do if i ~= 2 then parsedArgs[i == 1 and 1 or i - 1] = args[i] end end return (string.gsub( --…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)


Implements {{Redirect-distinguish-for}}.


mArguments = require('Module:Arguments')
mRedirectHatnote = require("Module:Redirect hatnote")

local p = {}

function p.redirectDistinguishFor(frame)
	local args = mArguments.getArgs(frame, {parentOnly = true})
	local maxArg = 0
	for k, v in pairs(args) do
		if type(k) == 'number' and k > maxArg then maxArg = k end
	end
	local parsedArgs = {}
	for i = 1, maxArg do
		if i ~= 2 then
			parsedArgs[i == 1 and 1 or i - 1] = args[i] end
	end
	return (string.gsub( --Note that the outer parentheses are necessary!
		mRedirectHatnote._redirect(parsedArgs, 1, {selfref = args.selfref}),
		"(redirects? here.)",
		"%1 Not to be confused with [[:" .. (args[2]:match('^:?(.*)')) .. "]].",
		1
	))
end

return p