Add pygments colors to pandoc stylesheet

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

View File

@ -1,7 +1,14 @@
## `nothing`
## `nil`
```
this is jsut some test
this block has no label
```
## `snickerdoodle`
```snickerdoodle
This block's lable is set so something that doesn't exist.
```
## `heex`

View File

@ -30,7 +30,8 @@ pre.numberSource code > span > a:first-child::before
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #7a7c7d; padding-left: 4px; }
div.sourceCode
{ color: #cfcfc2; background-color: #232629; }
/* { color: #cfcfc2; background-color: #232629; } */
{ background: #282a36; color: #f8f8f2; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
@ -39,29 +40,47 @@ code span.al { color: #95da4c; background-color: #4d1f24; font-weight: bold; } /
code span.an { color: #3f8058; } /* Annotation */
code span.at { color: #2980b9; } /* Attribute */
code span.bn { color: #f67400; } /* BaseN */
code span.bu { color: #7f8c8d; } /* BuiltIn */
/* code span.bu { color: #7f8c8d; } /* BuiltIn */
/* code span.bu { color: #f8f8f2; font-style: italic } /* Name.Builtin.Pseudo */
code span.bu { color: #8be9fd; font-style: italic } /* Name.Builtin */
code span.cf { color: #fdbc4b; font-weight: bold; } /* ControlFlow */
code span.ch { color: #3daee9; } /* Char */
code span.cn { color: #27aeae; font-weight: bold; } /* Constant */
code span.co { color: #7a7c7d; } /* Comment */
/* code span.ch { color: #3daee9; } /* Char */
code span.ch { color: #bd93f9 } /* Literal.String.Char */
/* code span.cn { color: #27aeae; font-weight: bold; } /* Constant */
code span.cn { color: #ff79c6 } /* Keyword.Constant */
/* code span.co { color: #7a7c7d; } /* Comment */
code span.co { color: #6272a4 } /* Comment */
code span.cv { color: #7f8c8d; } /* CommentVar */
code span.do { color: #a43340; } /* Documentation */
code span.dt { color: #2980b9; } /* DataType */
code span.dv { color: #f67400; } /* DecVal */
code span.er { color: #da4453; text-decoration: underline; } /* Error */
/* code span.dt { color: #2980b9; } /* DataType */
code span.dt { color: #8be9fd } /* Keyword.Type */
/* code span.dv { color: #f67400; } /* DecVal */
code span.dv { color: #ffb86c } /* Literal.Number.Float */
/*code span.er { color: #da4453; text-decoration: underline; } /* Error */
code span.er { color: #f8f8f2 } /* Error */
code span.ex { color: #0099ff; font-weight: bold; } /* Extension */
code span.fl { color: #f67400; } /* Float */
code span.fu { color: #8e44ad; } /* Function */
/* code span.fl { color: #f67400; } /* Float */
code span.fl { color: #ffb86c } /* Literal.Number.Float */
/* code span.fu { color: #8e44ad; } /* Function */
code span.fu { color: #50fa7b } /* Name.Function */
code span.im { color: #27ae60; } /* Import */
code span.in { color: #c45b00; } /* Information */
code span.kw { color: #cfcfc2; font-weight: bold; } /* Keyword */
code span.op { color: #cfcfc2; } /* Operator */
code span.ot { color: #27ae60; } /* Other */
/* code span.kw { color: #cfcfc2; font-weight: bold; } /* Keyword */
code span.kw { color: #ff79c6 } /* Keyword */
/* code span.op { color: #cfcfc2; } /* Operator */
code span.op { color: #ff79c6; } /* Operator */
/* code span.ot { color: #27ae60; } /* Other */
code span.ot { color: #f8f8f2 } /* Other */
code span.pp { color: #27ae60; } /* Preprocessor */
code span.re { color: #2980b9; background-color: #153042; } /* RegionMarker */
code span.sc { color: #3daee9; } /* SpecialChar */
code span.ss { color: #da4453; } /* SpecialString */
code span.st { color: #f44f4f; } /* String */
code span.va { color: #27aeae; } /* Variable */
/* code span.st { color: #f44f4f; } /* String */
code span.st { color: #bd93f9; } /* String */
/* code span.va { color: #27aeae; } /* Variable */
code span.va { color: #8be9fd; font-style: italic; } /* Variable */
code span.vs { color: #da4453; } /* VerbatimString */
code span.wa { color: #da4453; } /* Warning */

View File

@ -6,8 +6,9 @@ return {
_with_0:write(block.text)
_with_0:close()
end
local cmd = "pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s"
if block.classes[1] == "moon" or block.classes[1] == "moonscript" then
local p = io.popen(("pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l moonscript.py %s -x"):format(fname))
local p = io.popen((cmd .. " -x"):format("moonscript.py", fname))
local out = p:read("*a")
p:close()
return pandoc.RawBlock("html", out)
@ -25,10 +26,19 @@ return {
end
else
local status, handle_or_error = pcall(function()
return io.popen(("pygmentize -f html -O style=dracula,wrapcode,classprefix=py- -l %s %s"):format(block.classes[1], fname))
return io.popen((cmd):format(block.classes[1], fname))
end)
local sout = handle_or_error:read("*a")
return pandoc.RawBlock("html", sout)
if sout:len() == 0 then
local cb = pandoc.CodeBlock(block.text, {
class = "sourceCode"
})
return pandoc.Div(cb, {
class = "sourceCode"
})
else
return pandoc.RawBlock("html", sout)
end
end
end
end

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

View File

@ -125,7 +125,7 @@ sitegen.create =>
template: "post"
title: "Code Syntax Highlight Samples"
publish_date: format_date date true
add_all files_from "docs"
-- add_all files_from "docs"
copy "app.css"
copy "moonscript.css"