From c7be2a9fa9a457664e85af4a47602ed4f9a1f83b Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 1 Nov 2024 01:46:06 +0000 Subject: fine, ill do it your way --- init.lua | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index abd0f2f..c4358ca 100644 --- a/init.lua +++ b/init.lua @@ -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