Module:Anchor: Difference between revisions

    From Nonbinary Wiki
    m>Mr. Stradivarius
    m (Protected Module:Anchor: High-risk Lua module: 20,000 transclusions ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite)))
    m (3 revisions imported from templatewiki:Module:Anchor)
     
    (One intermediate revision by one other user not shown)
    (No difference)

    Latest revision as of 09:59, 16 November 2019

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

    -- This module implements {{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 anchors = {...}
    	local ret = {}
    	for _, anchor in ipairs(anchors) do
    		ret[#ret + 1] = '<span id="' .. anchor .. '"></span>'
    	end
    	return table.concat(ret)
    end
    
    return p