Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Orbit-style Htmlification using LuaExpatUtils
--[[
See http://steved-imaginaryreal.blogspot.com/2011/09/htmlification-with-lua.html
Example usage:
-- test2.lua
require 'html'
html {
body { title 'Test' },
h2 'title',
p 'first para',
p 'second para'
}
]]
doc = require 'lxp.doc'
setmetatable(_G,{
__index = function(t,name)
_G[name] = doc.tags(name)
return _G[name]
end
})
table_,html_ = doc.tags 'table,html'
function html(spec)
local d = doc.tostring(html_(spec),'',' ')
local name
if arg then -- not interactive
name = arg[0]:match('([%w_%-]+)%.lua')
end
if name then
local f = io.open(name..'.html','w')
f:write(d)
f:close()
else
print(d)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment