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,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