Skip to content

Instantly share code, notes, and snippets.

@stevedonovan
Created September 5, 2011 09:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevedonovan/1194576 to your computer and use it in GitHub Desktop.
Save stevedonovan/1194576 to your computer and use it in GitHub Desktop.
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