Moduł:Tekst

Z Wikipedii, wolnej encyklopedii
 Dokumentacja modułu [stwórz] [odśwież]
local function ExtraText(text)
	local extra = mw.ustring.char(9676)
	local data = mw.loadData("Moduł:IPA/data")
	local first = mw.ustring.codepoint(text, 1, 1)
	local last = mw.ustring.codepoint(text, -1, -1)
	local prefix
	if (first == 9676) and (mw.ustring.len(text) > 1) then
		text = mw.ustring.sub(text, 2, nil)
		prefix = extra
	else
		prefix = (data.combining[first] or data.joining[first]) and extra or ""
	end
	local suffix = data.joining[last] and extra or ""
	return prefix, suffix, text
end

return {
	
Tekst = function(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local result = {}
	local text = args[1]
	if text and (#text > 0) then
		local s = mw.text.decode(text, true)
		local prefix, suffix, text = ExtraText(s)
		return prefix..text..suffix
	end
	
	return text
end,

Utf8 = function(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local result = {}
	local text = args[1]
	if text and (#text > 0) then
		local s = mw.text.decode(text, true)
		local prefix, suffix, s = ExtraText(s)
		if #prefix > 0 then
			table.insert(result, prefix)
		end
		
		for c in s:gmatch"." do
			local b = c:byte(1,1)
			table.insert(result, string.format("%02x", b))
		end
		
		if #suffix > 0 then
			table.insert(result, suffix)
		end
	end
	
	mw.logObject(result, "result")
	return table.concat(result, " ")
end,

Unikod = function(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local result = {}
	local text = args[1]
	if text and (#text > 0) then
		local s = mw.text.decode(text, true)
		local prefix, suffix, s = ExtraText(s)
		if #prefix > 0 then
			table.insert(result, prefix)
		end
		
		for codepoint in mw.ustring.gcodepoint(s) do
			table.insert(result, string.format("U+%04x", codepoint))
		end
		
		if #suffix > 0 then
			table.insert(result, suffix)
		end
	end
	
	mw.logObject(result, "result")
	return table.concat(result, " ")
end,

Encja = function(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local result = {}
	local text = args[1]
	if text and (#text > 0) then
		local s = mw.text.decode(text, true)
		local prefix, suffix, s = ExtraText(s)
		if #prefix > 0 then
			table.insert(result, prefix)
		end
		
		for codepoint in mw.ustring.gcodepoint(s) do
			table.insert(result, "&#"..tostring(codepoint)..";")
		end
		
		if #suffix > 0 then
			table.insert(result, suffix)
		end
	end
	
	mw.logObject(result, "result")
	return table.concat(result, "​")
end,
	
Html = function(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local result = {}
	local text = args[1]
	if text and (#text > 0) then
		local s = mw.text.decode(text, true)
		local prefix, suffix, s = ExtraText(s)
		return mw.text.nowiki(prefix..mw.text.encode(s)..suffix)
	end
end,
	
}