Module:User:Wpi31/IDS

export = {}

local IDchars = { ["⿰"] = 2,	["⿱"] = 2,	["⿲"] = 3,	["⿳"] = 3,	["⿴"] = 2,	["⿵"] = 2,	["⿶"] = 2,	["⿷"] = 2,	["⿸"] = 2,	["⿹"] = 2,	["⿺"] = 2,	["⿻"] = 2,	--	-- in future perhaps: https://www.unicode.org/L2/L2018/18012-irgn2273-four-new-idcs.pdf	[mw.ustring.char(0x2FFC)] = 2,	[mw.ustring.char(0x2FFD)] = 2,	[mw.ustring.char(0x2FFE)] = 1,	[mw.ustring.char(0x2FFF)] = 1,	-- }

local function scale_style(x, y)   local t = style="padding:0;    	display:inline-block;    	-webkit-transform:scale(%,$);    	-moz-transform:scale(%,$);    	-ms-transform:scale(%,$);    	-o-transform:scale(%,$);    	transform:scale(%,$);" t = t:gsub('%', x/100):gsub('$', y/100) return t end

local function find_IDS_length(t) local count = 1 local i = 1 while true do		count = count + (IDchars[t[i]] or 0) if i > count then return count end i = i + 1 count = count + 1 end end

local function make_table(t) if #t == 1 then return t	end for i in #t do		local c = t[i] if c == "⿻" then return error("⿻ is not supported.") end if IDchars[c] == 2 then local lookahead = 1 local sx = 50 if t[i+1] == '@' then lookahead = 4 sa = tonumber(t:sub(i+2, i+3)) or error("invalid size specified at position "..i+2) end local lena = find_IDS_length(t:sub(lookahead)) if c == "⿰" then return {|style="margin:0px; border-spacing:0px;display:inline-block"					..scale_style(sa, 100)..make_table(t:sub(lookahead+1,lookahead+lena)).."||" .. scale_style(100-sa, 100)..make_table(t:sub(lookahead+lena+1)).."|}" elseif c == "⿱" then return {|style="margin:0px; border-spacing:0px;display:inline-block"					..scale_style(100, sa)..make_table(t:sub(lookahead+1,lookahead+lena)).."\n|-\n|" .. scale_style(100, 100-sa)..make_table(t:sub(lookahead+lena+1)).."|}" else error("unsupported IDS") end elseif IDchars[c] == 3 then stack:insert(c) if t[c+1] == '@' then local sa, sb, sc			end else end end end

function export.draw(frame) local args = frame:getParent.args local t = args[1] local text = "" make_table(t) return text end

return export