Created
September 5, 2011 09:40
-
-
Save stevedonovan/1194576 to your computer and use it in GitHub Desktop.
Orbit-style Htmlification using LuaExpatUtils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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