Module:Twemoji: Difference between revisions

From Irony Wiki
Jump to navigation Jump to search
how did i just now realize how to do this
 
m Reverted edit by Keys (talk) to last revision by Saucy
Tags: Rollback Mobile edit Mobile web edit Advanced mobile edit
 
(6 intermediate revisions by 2 users not shown)
Line 4: Line 4:


function p.main(frame)
function p.main(frame)
local p1 = frame[1]
local inp = frame.args[1]
local p2 = ""
local beginspan = "<span class='nowrap'>"
local p3 = ""
local size = "20px"
if (frame[2])
if (frame.args[2] and not(frame.args[2] == ""))
then
then
p2 = frame[2]
beginspan = "<span class='nowrap' title='" .. frame.args[2] .. "'>"
end
end
if (frame[3])
if (frame.args[3] and not(frame.args[3] == ""))
then
then
p3 = frame[3]
size = frame.args[3]
end
end
if (mw.ustring.match(p1, "[A-z0-9-]"))
if (mw.ustring.match(inp, "[A-z0-9-]"))
then
then
return "{{inline emote|Twemoji12 " .. p1 .. ".svg|2=" .. p2 .. "|3=" .. p3 .. "}}"
return beginspan .. "[[File:Twemoji12 " .. inp .. ".svg|".. size .."|link=|alt=]]</span>"
else
else
local cps = {}
local cps = {}
local i = 1
local i = 1
for codepoint in mw.ustring.gcodepoint(p1) do
for codepoint in mw.ustring.gcodepoint(inp) do
cps[i] = string.format("%x", codepoint)
cps[i] = string.format("%x", codepoint)
i = i + 1
i = i + 1
Line 32: Line 32:
local output = table.concat(cps, "-")
local output = table.concat(cps, "-")
return "{{inline emote|Twemoji12 " .. output .. ".svg|2=" .. p2 .. "|3=" .. p3 .. "}}"
return beginspan .. "[[File:Twemoji12 " .. output .. ".svg|".. size .."|link=|alt=" .. inp .. "]]</span>"
end
end
end
end


return p
return p

Latest revision as of 20:19, 16 September 2024

Documentation for this module may be created at Module:Twemoji/doc

-- Implements Template:Twemoji

local p = {}

function p.main(frame)
	local inp = frame.args[1]
	local beginspan = "<span class='nowrap'>"
	local size = "20px"
	
	if (frame.args[2] and not(frame.args[2] == ""))
	then
		beginspan = "<span class='nowrap' title='" .. frame.args[2] .. "'>"
	end
	
	if (frame.args[3] and not(frame.args[3] == ""))
	then
		size = frame.args[3]
	end
	
	if (mw.ustring.match(inp, "[A-z0-9-]"))
	then
		return beginspan .. "[[File:Twemoji12 " .. inp .. ".svg|".. size .."|link=|alt=]]</span>"
	else
		local cps = {}
		local i = 1
		
		for codepoint in mw.ustring.gcodepoint(inp) do
			cps[i] = string.format("%x", codepoint)
			i = i + 1
		end
		
		local output = table.concat(cps, "-")
		
		return beginspan .. "[[File:Twemoji12 " .. output .. ".svg|".. size .."|link=|alt=" .. inp .. "]]</span>"
	end
end

return p