Refactor pygments.moon
This commit is contained in:
@@ -1,30 +1,26 @@
|
||||
CodeBlock: (block) ->
|
||||
{ label } = block.classes
|
||||
cmd = "pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s"
|
||||
fname = os.tmpname!
|
||||
|
||||
with io.open fname, "w"
|
||||
\write block.text
|
||||
\close!
|
||||
|
||||
cmd = "pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s"
|
||||
|
||||
if block.classes[1] == "moon" or block.classes[1] == "moonscript"
|
||||
p = io.popen (cmd .. " -x")\format "moonscript.py", fname
|
||||
out = p\read"*a"
|
||||
p\close!
|
||||
pandoc.RawBlock "html", out
|
||||
else
|
||||
if block.classes[1] == nil or block.classes[1] == "heex"
|
||||
if block.classes[1] == nil
|
||||
cb = pandoc.CodeBlock(block.text, class: "sourceCode")
|
||||
pandoc.Div cb, class: "sourceCode"
|
||||
else
|
||||
block
|
||||
switch label
|
||||
when "moon", "moonscript"
|
||||
p = io.popen (cmd .. " -x")\format "moonscript.py", fname
|
||||
out = with p\read"*a"
|
||||
p\close!
|
||||
-- syntax highlight with pygments
|
||||
pandoc.RawBlock "html", out
|
||||
else
|
||||
status, handle_or_error = pcall ->
|
||||
io.popen (cmd)\format block.classes[1], fname
|
||||
status, handle = pcall -> io.popen cmd\format label or "text", fname
|
||||
out = handle\read"*a"
|
||||
|
||||
sout = handle_or_error\read"*a"
|
||||
if sout\len! == 0
|
||||
cb = pandoc.CodeBlock(block.text, class: "sourceCode")
|
||||
pandoc.Div cb, class: "sourceCode"
|
||||
if out\len! == 0
|
||||
-- syntax highlight with pandoc
|
||||
block
|
||||
else
|
||||
pandoc.RawBlock "html", sout
|
||||
-- syntax highlight with pygments
|
||||
pandoc.RawBlock "html", out
|
||||
|
||||
Reference in New Issue
Block a user