diff options
author | ubq323 <ubq323@ubq323.website> | 2024-11-01 01:46:06 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-11-01 01:46:06 +0000 |
commit | c7be2a9fa9a457664e85af4a47602ed4f9a1f83b (patch) | |
tree | 73046606293a32704f7bcc85a1703c4b4d0555d8 | |
parent | ef4207a7f6d85f2a33fa1889299dedc2270df856 (diff) |
fine, ill do it your way
-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) |