Refactor pygments.moon

This commit is contained in:
2025-06-16 20:18:05 -07:00
parent a4258167df
commit 41baffb445
7 changed files with 52 additions and 59 deletions

View File

@@ -1,44 +1,33 @@
return {
CodeBlock = function(block)
local label
label = block.classes[1]
local cmd = "pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s"
local fname = os.tmpname()
do
local _with_0 = io.open(fname, "w")
_with_0:write(block.text)
_with_0:close()
end
local cmd = "pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s"
if block.classes[1] == "moon" or block.classes[1] == "moonscript" then
local _exp_0 = label
if "moon" == _exp_0 or "moonscript" == _exp_0 then
local p = io.popen((cmd .. " -x"):format("moonscript.py", fname))
local out = p:read("*a")
p:close()
local out
do
local _with_0 = p:read("*a")
p:close()
out = _with_0
end
return pandoc.RawBlock("html", out)
else
if block.classes[1] == nil or block.classes[1] == "heex" then
if block.classes[1] == nil then
local cb = pandoc.CodeBlock(block.text, {
class = "sourceCode"
})
return pandoc.Div(cb, {
class = "sourceCode"
})
else
return block
end
local status, handle = pcall(function()
return io.popen(cmd:format(label or "text", fname))
end)
local out = handle:read("*a")
if out:len() == 0 then
return block
else
local status, handle_or_error = pcall(function()
return io.popen((cmd):format(block.classes[1], fname))
end)
local sout = handle_or_error:read("*a")
if sout:len() == 0 then
local cb = pandoc.CodeBlock(block.text, {
class = "sourceCode"
})
return pandoc.Div(cb, {
class = "sourceCode"
})
else
return pandoc.RawBlock("html", sout)
end
return pandoc.RawBlock("html", out)
end
end
end