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

local p = {}

local styles = {
	["0"] = "color: #000;";
	["1"] = "color: #00A;";
	["2"] = "color: #0A0;";
	["3"] = "color: #0AA;";
	["4"] = "color: #A00;";
	["5"] = "color: #A0A;";
	["6"] = "color: #AA0;";
	["7"] = "color: #AAA;";
	["8"] = "color: #555;";
	["9"] = "color: #55F;";
	a = "color: #5F5;";
	b = "color: #5FF;";
	c = "color: #F55;";
	d = "color: #F5F;";
	e = "color: #FF5;";
	f = "color: #FFF;";
	l = "font-weight: bold;";
	m = "text-decoration: line-through;";
	n = "text-decoration: underline";
	o = "font-style: italic;"
}

function p.parse(text, shadow)
	if shadow then
		styles["0"] = "color: #000; text-shadow: 2px 2px #000;";
		styles["1"] = "color: #00A; text-shadow: 2px 2px #00002A;";
		styles["2"] = "color: #0A0; text-shadow: 2px 2px #002A00;";
		styles["3"] = "color: #0AA; text-shadow: 2px 2px #002A2A;";
		styles["4"] = "color: #A00; text-shadow: 2px 2px #2A0000;";
		styles["5"] = "color: #A0A; text-shadow: 2px 2px #2A002A;";
		styles["6"] = "color: #FA0; text-shadow: 2px 2px #2A2A00;";
		styles["7"] = "color: #AAA; text-shadow: 2px 2px #2A2A2A;";
		styles["8"] = "color: #555; text-shadow: 2px 2px #151515;";
		styles["9"] = "color: #55F; text-shadow: 2px 2px #15153F;";
		styles.a = "color: #5F5; text-shadow: 2px 2px #153F15;";
		styles.b = "color: #5FF; text-shadow: 2px 2px #153F3F;";
		styles.c = "color: #F55; text-shadow: 2px 2px #3F1515;";
		styles.d = "color: #F5F; text-shadow: 2px 2px #3F153F;";
		styles.e = "color: #FF5; text-shadow: 2px 2px #3F3F15;";
		styles.f = "color: #FFF; text-shadow: 2px 2px #3F3F3F;";
	end
	local out = {}
	local i = 1
	local j = 1
	local depth = 0
	while true do
		if text:sub(j, j + 1) == "§" then
			out[#out + 1] = text:sub(i, j - 1)
			i = j + 2
			local c = text:sub(i, i)
			i = i + 1
			j = i
			if c == "r" then
				for k = 1, depth do out[#out + 1] = "</span>"
				depth = 0
			end else
				out[#out + 1] = "<span style=\""
				out[#out + 1] = styles[c]
				out[#out + 1] = "\">"
				depth = depth + 1
			end
		elseif j == #text then
			out[#out + 1] = text:sub(i, j)
			for k = 1, depth do
				out[#out + 1] = "</span>"
			end
			return table.concat(out)
		else j = j + 1 end
	end
end

function p.main(frame)
	return p.parse(frame.args[1], frame.args.shadow ~= nil)
end

return p