模块:Invisible anchor
模块文档[创建]
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。本模块的子页面。 |
--模塊嵌入{{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