diff options
-rw-r--r-- | init.lua | 33 |
1 files changed, 11 insertions, 22 deletions
@@ -2,28 +2,17 @@ local html = require'garkup.html' local T = html.T local prose = require'garkup.prose' -function empipe(prog, input) - local posix = require'posix' - local unistd = posix.unistd or require'posix.unistd' - local pipe = assert(posix.popen_pipeline({ - function() io.write(input) end, - prog - }, "r")) - local output = "" - repeat - local next = assert(unistd.read(pipe.fd, 8192)) - output = output .. next - until #next == 0 - assert(posix.pclose(pipe)) - return output -end - -function highlight(code, lang) - local highlighted = empipe( - {"highlight", "-f", "-S", lang, "--inline-css", "--enclose-pre"}, - code - ) - return html.safe(highlighted) +local function highlight(code, lang) + -- you'd better not already be using that file + local infile = assert(io.open("/tmp/highlighter_input","w")) + assert(infile:write(code)) + local outhandle = assert(io.popen("highlight -f -S "..lang.." --inline-css --enclose-pre </tmp/highlighter_input", "r")) + local output = assert(outhandle:read"a") + + outhandle:close() + infile:close() + + return html.safe(output) end local function mode_code(S) |