miti.sh/pygments.lua
2025-06-16 20:18:05 -07:00

27 lines
785 B
Lua

return {
CodeBlock = function(block)
local fname = os.tmpname()
do
local _with_0 = io.open(fname, "w")
_with_0:write(block.text)
_with_0:close()
end
if block.classes[1] == "moon" or block.classes[1] == "moonscript" then
local p = io.popen(("pygmentize -f html -l moonscript.py %s -x"):format(fname))
local out = p:read("*a")
p:close()
return pandoc.RawBlock("html", out)
else
local status, handle_or_error = pcall(function()
return io.popen(("pygmentize -f html -l %s %s"):format(block.classes[1], fname))
end)
local sout = handle_or_error:read("*a")
if block.classes[1] == "heex" then
return block
else
return pandoc.RawBlock("html", sout)
end
end
end
}