Jump to content

Module:Sandbox/Jbzdarkid/NecroTable: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Jbzdarkid (talk | contribs)
mNo edit summary
Tag: Reverted
Jbzdarkid (talk | contribs)
m Undid revision 1140228069 by Jbzdarkid (talk)
 
Line 20: Line 20:


local style = 'width:28px' .. (color and (';background-color:' .. color) or '')-- Convert color into a style attribute
local style = 'width:28px' .. (color and (';background-color:' .. color) or '')-- Convert color into a style attribute
local contents = image or text -- fallback text I guess
local contents = image and ('[[File:' .. image .. '|24x24px]]') or text -- Convert image into a wiki link, or fall back to raw text (if provided)


output = output .. '<td style="' .. style .. '">' .. contents .. '</td>'
output = output .. '<td style="' .. style .. '">' .. contents .. '</td>'

Latest revision as of 02:28, 19 February 2023

local p = {}

function p.table(frame)
	local output = '<table cellpadding="0" style="margin:0px; border:1px; border-color:black; border-collapse:collapse; background-color:lightgray; text-align:center">'
	output = output .. '<tr style="height:28px">'
	local grid = frame.args['grid']
	for j = 1, #grid do
		local chr = grid:byte(j)
		if (chr == string.byte("\n")) then output = output .. '</tr><tr style="height:28px">' end
		if (chr == string.byte("."))  then output = output .. '<td style="width:28px"></td>' end
		if (chr == string.byte("^"))  then output = output .. '<td style="width:28px; background-color:skyblue">↑</td>' end
		if (chr == string.byte("v"))  then output = output .. '<td style="width:28px; background-color:skyblue">↓</td>' end
		if (chr == string.byte("<"))  then output = output .. '<td style="width:28px; background-color:skyblue">←</td>' end
		if (chr == string.byte(">"))  then output = output .. '<td style="width:28px; background-color:skyblue">→</td>' end
		if (chr >= string.byte("1") and chr <= string.byte("9")) then
			local ord = chr - string.byte("0")
			local color = frame.args['color-' .. ord]
			local image = frame.args['image-' .. ord]
			local text = frame.args['text-' .. ord] or ''

			local style = 'width:28px' .. (color and (';background-color:' .. color) or '')-- Convert color into a style attribute
			local contents = image and ('[[File:' .. image .. '|24x24px]]') or text -- Convert image into a wiki link, or fall back to raw text (if provided)

			output = output .. '<td style="' .. style .. '">' .. contents .. '</td>'
		end
	end
	output = output .. '</tr></table>'
	return output
end

return p