Module:category link

From Wiktionary, the free dictionary
Jump to navigation Jump to search


local concat = table.concat
local html_create = mw.html.create
local is_valid_title = require("Module:pages").is_valid_title
local make_title = mw.title.makeTitle
local tostring = tostring

local export = {}

function export.make_link(name, sortkey)
	-- Unconditionally add the "Category:" prefix.
	local fullname = "Category:" .. name
	if is_valid_title(make_title(14, name)) then
		fullname = "[[:" .. fullname .. "]]"
	end
	
	return tostring(html_create("code")
		:css("white-space", "pre-wrap")
		:css("background-color", "inherit")
		:wikitext("[[" .. concat({fullname, sortkey}, "|") .. "]]")
	)
end

return export