Module:anchors

From Wiktionary, the free dictionary
(Redirected from Module:senseid)
Jump to navigation Jump to search
This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local anchor_encode = mw.uri.anchorEncode
local html_create = mw.html.create
local tostring = tostring

local export = {}

function export.language_anchor(lang, id)
	return anchor_encode(lang:getFullName() .. ": " .. id)
end

function export.make_anchors(ids)
	local anchors = html_create()
	for i = 1, #ids do
		anchors = anchors:tag("span")
			:addClass("template-anchor")
			:attr("id", anchor_encode(ids[i]))
			:done()
	end
	return tostring(anchors:allDone())
end

function export.senseid(lang, id, tag_name)
	-- The following tag is opened but never closed, where is it supposed to be closed?
	--         with <li> it doesn't matter, as it is closed automatically.
	--         with <p> it is a problem
	
	-- Any spaces in the ID attribute are replaced with underscores
	-- by the wikitext parser.
	local ret = html_create(tag_name)
		:addClass("senseid")
		:attr("id", export.language_anchor(lang, id))
		:allDone()
	return (tostring(ret)
		:gsub("</" .. tag_name .. ">", "")
	)
end

function export.etymid(lang, id)
	return tostring(html_create("span")
		:addClass("etymid")
		:attr("id", export.language_anchor(lang, id))
		:allDone()
	)
end


return export