34 lines
734 B
Plaintext
34 lines
734 B
Plaintext
CodeBlock: (block) ->
|
|
{ label } = block.classes
|
|
fname, errfname = os.tmpname!, os.tmpname!
|
|
cmd = "pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s 2>%s"
|
|
|
|
with io.open fname, "w"
|
|
\write block.text
|
|
\close!
|
|
|
|
lexer = switch label
|
|
when "moon", "moonscript"
|
|
cmd = cmd .. " -x"
|
|
"moonscript.py"
|
|
else
|
|
label or "text"
|
|
|
|
f = io.popen cmd\format lexer, fname, errfname
|
|
|
|
out = with f\read"*a"
|
|
f\close!
|
|
|
|
if out == ""
|
|
e = io.open errfname, "r"
|
|
|
|
err = with e\read"*a"
|
|
e\close!
|
|
|
|
assert err\match("Error: no lexer for alias '#{label}' found"),
|
|
"Failed to parse pygmentize result, is pygments installed?"
|
|
|
|
block
|
|
else
|
|
pandoc.RawBlock "html", out
|