Jump to content

Module:links/print data

Hali sa Wiksyunaryo

Prints the items in Module:links/data.


local export = {}

local function make_anchor(text, anchor)
	return '<span id="' .. (anchor or text) .. '">' .. text .. '</span>'
end

function export.show()
	local data		= mw.loadData "Module:links/data"
	local output	= {}
	
	local insert		= table.insert
	local ugsub			= mw.ustring.gsub
	local get_codepoint = mw.ustring.codepoint
	local ulen			= mw.ustring.len
	local sorted_pairs	= require "Module:table".sortedPairs
	local is_whitespace = require "Module:Unicode data".is_whitespace
	local get_script = require "Module:Unicode data".find_best_script
	
	local function process_link_text (link_text)
		-- The basic space character is stripped from link text if there are no
		-- characters surrounding it.
		if ulen(link_text) == 1 and is_whitespace(get_codepoint(link_text)) then
			return ("]%s["):format(link_text)
		else
			-- Convert all characters to hexadecimal character entities to
			-- prevent any transformations.
			-- This is pretty much only because HTML comment syntax would not be
			-- displayed otherwise. But who knows what else MediaWiki software
			-- might do.
			return ugsub(
				link_text,
				".",
				function (char)
					local codepoint = get_codepoint(char)
					if is_whitespace(codepoint) then
					else
						return ("&#x%X;"):format(codepoint)
					end
				end)
		end
	end
	
	local function link(term, title)
		local script = get_script(term)
		if script ~= "None" then
			return ('* <span class="%s">[[Unsupported titles/%s|%s]]</span>'):format(
				script,
				title,
				process_link_text(term))
		else
			return ("* [[Unsupported titles/%s|%s]]"):format(
				title,
				process_link_text(term))
		end
	end
	
	for term, title in sorted_pairs(data.unsupported_titles) do
		insert(output, link(term, title))
	end
	insert(output, 1, "; " .. make_anchor("Unsupported titles") .. ":")
	
	insert(output, "; " .. make_anchor("High-memory entries") .. ":")
	for entry in sorted_pairs(data.high_memory_entries) do
		insert(output, ("* [[%s]]"):format(entry))
	end
	
	return table.concat(output, "\n")
end

return export