Add pygments colors to pandoc stylesheet

This commit is contained in:
2025-06-16 20:18:05 -07:00
parent 5bf9a45007
commit d634dbd3f5
5 changed files with 69 additions and 24 deletions

View File

@@ -4,8 +4,11 @@ CodeBlock: (block) ->
\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 ("pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l moonscript.py %s -x")\format fname
-- p = io.popen ("pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l moonscript.py %s -x")\format fname
p = io.popen (cmd .. " -x")\format "moonscript.py", fname
-- p = io.open fname
out = p\read"*a"
@@ -26,16 +29,22 @@ CodeBlock: (block) ->
-- pandoc.CodeBlock block.text, "text"
else
status, handle_or_error = pcall ->
io.popen ("pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s")\format block.classes[1], fname
io.popen (cmd)\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 sout\len! == 0
cb = pandoc.CodeBlock(block.text, class: "sourceCode")
pandoc.Div cb, class: "sourceCode"
else
pandoc.RawBlock "html", sout
-- if mat = sout\match('<div class="highlight"><pre>(.-)\n?</pre></div>')
-- rep = '<div class="sourceCode"><pre class="sourceCode ' .. block.classes[1] .. '"><code class="sourceCode ' .. block.classes[1] .. '">' .. mat .. '</code></pre></div>'
-- sout = sout\gsub('<div class="highlight"><pre>(.-)\n?</pre></div>', rep)
pandoc.RawBlock "html", sout
-- pandoc.RawBlock "html", sout
-- sout = if status then "true" else "false"
-- pandoc.RawBlock "html", sout
-- if mat = out\match('<div class="highlight"><pre>(.-)\n?</pre></div>')
-- rep = '<div class="sourceCode"><pre class="sourceCode ' .. 'moonscript"><code class="sourceCode ' .. 'moonscript">' .. mat .. '</code></pre></div>'