Module:Sandbox/XarrotD

local p = {} local result = {}

function p:TestHTML(frame) local div1 = mw.html.create( 'ul' ) local div1sub = mw.html.create( 'li' ) div1sub:wikitext( 'This is some text.' ) div1:node( div1sub ) local div2 = mw.html.create( 'ul' ) local div2sub = mw.html.create( 'li' ) div2sub:wikitext( 'This is some more text.' ) div2:node( div2sub ) local div3 = mw.html.create( 'ul' ) local div3sub = mw.html.create( 'li' ) div3sub:wikitext( 'This is also text.' ) div3:node( div3sub ) local div = mw.html.create( 'div' ) div :attr( 'class', 'list-columns' ) :css( 'column-width', '25em' ) :node( div1 ) :node( div2 ) :node( div3 ) return tostring(div) end

function p:TestHTML2(frame) return 'This is some text.' end

function p:TestHTML3(frame) local div1 = 		This is some text that will be formatted with a number later. The number is {number}.		 table.insert(result, div1) local div2 = 		This is some more text that will be formatted with a different number. The number is {number}.		 table.insert(result, div2) local div3 = 		This is even more text that will be formatted with an even differenter number. The number is {number}.		 table.insert(result, div3) return table.concat(result, '') end

function p:TestHTML4(frame) local div1 = This is some text that will be formatted with a number later. The number is %s. div1 = string.format(div1, frame.args[2]) table.insert(result, div1) local div2 = This is some more text that will be formatted with a different number. The number is %s.</li></ul> div2 = string.format(div2, frame.args[3]) table.insert(result, div2) local div3 = This is even more text that will be formatted with an even differenter number. The number is %s.</li></ul> div3 = string.format(div3, frame.args[4]) table.insert(result, div3) return table.concat(result, '') end

function p:ParseAndHTMLConvert(inp) local ul = mw.html.create( 'ul' ) for i, v in ipairs(inp) do		if v.parse_type == 0 then -- object is already evaluated data = v		elseif v.parse_type == 1 then -- object is not evaluated, run its func data = v.func end

local li = mw.html.create( 'li' ) formatted_text = string.gsub(data.unparsed_str, "{%a+}", function(s)			return data.repl[string.match(s, "%a+")]		end) li:wikitext( formatted_text ) if data.subs ~= nil then li:node(p:ParseAndHTMLConvert(data.subs)) end ul:node( li ) end return ul end

function p.Replacement(s, repl) return repl[string.match(s, "%a+")] end

function p.Generate(frame) if frame.args[1] == '1' then return p:TestHTML(frame) elseif frame.args[1] == '2' then return p:TestHTML2(frame) elseif frame.args[1] == '3' then return p:TestHTML3(frame) elseif frame.args[1] == '4' then return p:TestHTML4(frame) elseif frame.args[1] == '5' then subs = {} subs.one = "one"; subs.two = 2; subs.three = 3.456789123456789 p1 = {} p1.unparsed_str = "Test string 1, the values are {one} {two} {three}" p1.repl = subs p1.parse_type = 0 p2 = {} p2.unparsed_str = "Test string 2, the values are {one} {two} {three}" p2.repl = subs p2.parse_type = 0 p2sub = {} p2sub.unparsed_str = "Test substring 1, the values are {one} {two} {three}" p2sub.repl = subs p2sub.parse_type = 0 p2.subs = {p2sub} inp = {p1, p2} return tostring(p:ParseAndHTMLConvert(inp)) end end

return p