-
Notifications
You must be signed in to change notification settings - Fork 8
/
demo.lua
47 lines (40 loc) · 1.44 KB
/
demo.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- Run this Lua script from the project root.
function readfile(path)
local handle = assert(io.open(path))
local data = assert(handle:read '*a')
assert(handle:close()); return data
end
function writefile(path, colors, data)
local handle = assert(io.open(path, 'w'))
local lxsh = require 'lxsh'
assert(handle:write([[
<html>
<head>
<style type="text/css">
html, body { margin: 0; padding: 0; }
pre { margin: 0; padding: 1em; }
</style>
]],
lxsh.includestyles(colors, true),
'\n</head>\n<body>\n'))
assert(handle:write(data))
assert(handle:write '\n</body>\n</html>\n')
local nbytes = handle:seek()
assert(handle:close())
return nbytes
end
for _, colors in ipairs { 'earendel', 'slate', 'wiki' } do
options = { external = true }
-- Highlight example Lua source code (from my Lua/APR binding).
local highlighter = require 'lxsh.highlighters.lua'
local input = readfile 'examples/apr.lua'
local outfile = 'examples/' .. colors .. '/apr.lua.html'
local nbytes = writefile(outfile, colors, highlighter(input, options))
print(('Wrote %iK to %s'):format(nbytes/1024, outfile))
-- Highlight example C source code (also from my Lua/APR binding).
local highlighter = require 'lxsh.highlighters.c'
local input = readfile 'examples/lua_apr.c'
local outfile = 'examples/' .. colors .. '/lua_apr.c.html'
local nbytes = writefile(outfile, colors, highlighter(input, options))
print(('Wrote %iK to %s'):format(nbytes/1024, outfile))
end