lua-users home
lua-l archive

Re: Narcissus in Lua (Javascript parser)

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> untested:
Here it is, tested.
function H (tag, attrs, c, ...)
	o = {('<%s '):format(tag)}
	if attrs then
		for k,v in pairs(attrs) do
			table.insert (o, ('%s="%s" '):format(k,v))
		end
	end
	if c then
		table.insert (o,'>')
		table.insert (o, table.concat({c,...}))
		table.insert (o, ('</%s>'):format(tag))
	else
		table.insert (o, '/>')
	end
	table.insert (o, '\n')
	return table.concat(o)
end
print(
H('html',nil,
 H('head',nil, H('title',nil, 'page title')),
 H('body',nil,
 H('div', {id='header',class='banner'},
 H('p',nil, 'header div')),
 H('div', {id='main'},
 H('p',nil, 'main part'),
 H('img', {src='lolcats/purrr.jpg', alt='lol'}),
 H('a', {href='somewhere/else.html'}, 'lets go')),
 H('div',{id='footer'}, H('p',nil,'the end'))))
)

AltStyle によって変換されたページ (->オリジナル) /