From e041143b27d74fdeada245b889baa3531ca086e5 Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Mon, 16 Jun 2025 20:18:05 -0700 Subject: [PATCH] WIP --- pygments.lua | 23 +++++++++++++++++------ pygments.moon | 34 ++++++++++++++++++++++++++++------ renderers/markdown.moon | 6 +++--- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/pygments.lua b/pygments.lua index 70659be..0b145af 100644 --- a/pygments.lua +++ b/pygments.lua @@ -1,15 +1,26 @@ return { CodeBlock = function(block) + local fname = os.tmpname() + do + local _with_0 = io.open(fname, "w") + _with_0:write(block.text) + _with_0:close() + end if block.classes[1] == "moon" or block.classes[1] == "moonscript" then - local fname = os.tmpname() - do - local _with_0 = io.open(fname, "w") - _with_0:write(block.text) - _with_0:close() - end local p = io.popen(("pygmentize -f html -l moonscript.py %s -x"):format(fname)) local out = p:read("*a") + p:close() return pandoc.RawBlock("html", out) + else + local status, handle_or_error = pcall(function() + return io.popen(("pygmentize -f html -l %s %s"):format(block.classes[1], fname)) + end) + local sout = handle_or_error:read("*a") + if block.classes[1] == "heex" then + return block + else + return pandoc.RawBlock("html", sout) + end end end } diff --git a/pygments.moon b/pygments.moon index 58612bb..8e8bbaa 100644 --- a/pygments.moon +++ b/pygments.moon @@ -1,11 +1,33 @@ CodeBlock: (block) -> + fname = os.tmpname! + with io.open fname, "w" + \write block.text + \close! + if block.classes[1] == "moon" or block.classes[1] == "moonscript" - fname = os.tmpname! - with io.open fname, "w" - \write block.text - \close! - p = io.popen ("pygmentize -f html -l moonscript.py %s -x")\format fname - out = p\read"*a" + -- p = io.open fname + out = p\read"*a" + p\close! pandoc.RawBlock "html", out + -- pandoc.RawBlock "html", "moonscript" + else + status, handle_or_error = pcall -> + io.popen ("pygmentize -f html -l %s %s")\format block.classes[1], fname + -- io.open fname + + sout = handle_or_error\read"*a" + -- handle_or_error\close! + -- if sout\len! == 0 then block else pandoc.RawBlock "html", sout + if block.classes[1] == "heex" + -- pandoc.RawBlock "html", "heex" + block + else + pandoc.RawBlock "html", sout + + + -- p = io.open fname + -- out = p\read"*a" + -- p\close! + -- pandoc.RawBlock "html", out diff --git a/renderers/markdown.moon b/renderers/markdown.moon index 3b0230c..48a9299 100644 --- a/renderers/markdown.moon +++ b/renderers/markdown.moon @@ -25,9 +25,9 @@ class PandocRenderer extends require "sitegen.renderers.markdown" p = io.open fname out = p\read"*a" - if mat = out\match('
(.-)\n?
') - rep = '
' .. mat .. '
' - out = out\gsub('
(.-)\n?
', rep) + -- if mat = out\match('
(.-)\n?
') + -- rep = '
' .. mat .. '
' + -- out = out\gsub('
(.-)\n?
', rep) out