Add pygments colors to pandoc stylesheet

This commit is contained in:
2025-06-16 20:18:05 -07:00
parent 5bf9a45007
commit d634dbd3f5
5 changed files with 69 additions and 24 deletions

View File

@@ -6,8 +6,9 @@ return {
_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 p = io.popen(("pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l moonscript.py %s -x"):format(fname))
local p = io.popen((cmd .. " -x"):format("moonscript.py", fname))
local out = p:read("*a")
p:close()
return pandoc.RawBlock("html", out)
@@ -25,10 +26,19 @@ return {
end
else
local status, handle_or_error = pcall(function()
return io.popen(("pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s"):format(block.classes[1], fname))
return io.popen((cmd):format(block.classes[1], fname))
end)
local sout = handle_or_error:read("*a")
return pandoc.RawBlock("html", sout)
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
end
end
end