42 lines
1.1 KiB
Lua
42 lines
1.1 KiB
Lua
return {
|
|
CodeBlock = function(block)
|
|
local label
|
|
label = block.classes[1]
|
|
local fname, errfname = os.tmpname(), os.tmpname()
|
|
local cmd = "pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s 2>%s"
|
|
do
|
|
local _with_0 = io.open(fname, "w")
|
|
_with_0:write(block.text)
|
|
_with_0:close()
|
|
end
|
|
local lexer
|
|
local _exp_0 = label
|
|
if "moon" == _exp_0 or "moonscript" == _exp_0 then
|
|
cmd = cmd .. " -x"
|
|
lexer = "moonscript.py"
|
|
else
|
|
lexer = label or "text"
|
|
end
|
|
local f = io.popen(cmd:format(lexer, fname, errfname))
|
|
local out
|
|
do
|
|
local _with_0 = f:read("*a")
|
|
f:close()
|
|
out = _with_0
|
|
end
|
|
if out == "" then
|
|
local e = io.open(errfname, "r")
|
|
local err
|
|
do
|
|
local _with_0 = e:read("*a")
|
|
e:close()
|
|
err = _with_0
|
|
end
|
|
assert(err:match("Error: no lexer for alias '" .. tostring(label) .. "' found"), "Failed to parse pygmentize result, is pygments installed?")
|
|
return block
|
|
else
|
|
return pandoc.RawBlock("html", out)
|
|
end
|
|
end
|
|
}
|