跳转到内容

模組:Invisible anchor

维基百科,自由的百科全书
文档图示 模块文档[创建]
--模塊嵌入{{Invisible anchor}}

local getArgs = require('Module:Arguments').getArgs
local tableTools = require('Module:TableTools')

local p = {}

function p.main(frame)
	-- Get the positional arguments from #invoke, remove any nil values,
	-- and pass them to p._main.
	local args = getArgs(frame)
	local argArray = tableTools.compressSparseArray(args)
	return p._main(unpack(argArray))
end

function p._main(...)
	-- Generate the list of anchors.
	local frame = mw.getCurrentFrame()
	local anchors = {...}
	local ret = {}
	for _, anchor in ipairs(anchors) do
		local anchor_name = '{{anchorencode:'.. anchor ..'}}'
		if mw.isSubsting() then anchor_name = '{{safesubst:anchorencode:'.. anchor ..'}}' end
		anchor_name = frame:preprocess(anchor_name)
		ret[#ret + 1] = 
		'<span class="hvanchor">'..
			'<span class="anchor" id="' .. anchor_name .. '"></span>'..
			'<span class="hvanchor-text">' .. anchor .. '</span>'..
		'</span>'
	end
	return table.concat(ret)
end

return p