コンテンツにスキップ

モジュール:Anchor

半永久的に拡張半保護されているモジュール
モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

このモジュールは{{Anchors}}を実装しています。詳しい説明についてはテンプレートの説明文をご参照ください。

-- This module implements {{anchor}}.

local yesno = require('Module:Yesno')
local getArgs = require('Module:Arguments').getArgs
local compressSparseArray = require('Module:TableTools').compressSparseArray

local p = {}

function p.main(frame)
	-- Get the positional arguments from #invoke and remove any nil values
	local visible = yesno(frame.args.visible, false)
	local args = getArgs(frame)
	local argArray = compressSparseArray(args)

	local ret = {}
	for i, el in ipairs(argArray) do
		local anchor = frame:callParserFunction('anchorencode', { el })
		anchor = mw.text.decode(anchor, true)
		if i == 1 and visible then
			local display = string.gsub(anchor, '_', ' ')
			table.insert(ret, display)
		end
		local node = mw.html.create('span')
			:attr('class', 'anchor')
			:attr('id', anchor)
		table.insert(ret, tostring(node))
	end

	return table.concat(ret)
end

return p