Module:Anchor

From Viki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Anchor/doc

 1 -- This module implements {{anchor}}.
 2 
 3 local getArgs = require('Module:Arguments').getArgs
 4 local tableTools = require('Module:TableTools')
 5 
 6 local p = {}
 7 
 8 function p.main(frame)
 9 	-- Get the positional arguments from #invoke, remove any nil values,
10 	-- and pass them to p._main.
11 	local args = getArgs(frame)
12 	local argArray = tableTools.compressSparseArray(args)
13 	return p._main(unpack(argArray))
14 end
15 
16 function p._main(...)
17 	-- Generate the list of anchors.
18 	local anchors = {...}
19 	local ret = {}
20 	for _, anchor in ipairs(anchors) do
21 		ret[#ret + 1] = '<span class="anchor" id="' .. anchor .. '"></span>'
22 	end
23 	return table.concat(ret)
24 end
25 
26 return p