Write Pandoc lua-filter in MoonScript and compile to Lua on build
This commit is contained in:
parent
46aa6c829f
commit
895ef13d73
15
pygments.lua
15
pygments.lua
@ -1,12 +1,15 @@
|
||||
function CodeBlock(block)
|
||||
return {
|
||||
CodeBlock = function(block)
|
||||
if block.classes[1] == "moon" or block.classes[1] == "moonscript" then
|
||||
local fname = os.tmpname()
|
||||
local handle = io.open(fname, "w")
|
||||
handle:write(block.text)
|
||||
handle:close()
|
||||
|
||||
local p = io.popen(string.format("pygmentize -f html -l moonscript.py %s -x", fname))
|
||||
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")
|
||||
return pandoc.RawBlock("html", out)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
11
pygments.moon
Normal file
11
pygments.moon
Normal file
@ -0,0 +1,11 @@
|
||||
CodeBlock: (block) ->
|
||||
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"
|
||||
|
||||
pandoc.RawBlock "html", out
|
11
site.moon
11
site.moon
@ -13,6 +13,9 @@ import p from require "moon" -- debug
|
||||
-- Change output dir to what Openresty prefers
|
||||
Site.config.out_dir = "html/"
|
||||
|
||||
-- Compile lua-filter used by Pandoc to highlight MoonScript syntax
|
||||
os.execute "moonc pygments.moon"
|
||||
|
||||
-- Configure the command our custom renderer uses to convert markdown to html
|
||||
rend = "renderers.markdown"
|
||||
require(rend).cmd = "pandoc --mathjax --lua-filter pygments.lua >"
|
||||
@ -120,13 +123,13 @@ sitegen.create =>
|
||||
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
||||
add_all files_from "docs"
|
||||
|
||||
copy "app.css"
|
||||
copy "moonscript.css"
|
||||
copy "pygments.css"
|
||||
|
||||
-- replace post markdown yaml headers with moonscript headers
|
||||
filter "docs", (body) =>
|
||||
body\gsub "^%-%-%-.-%.%.%.", (yaml_header) ->
|
||||
header = yaml_header\gsub "%-%-%-", "{"
|
||||
moonscript_header = header\gsub "%.%.%.", "}"
|
||||
moonscript_header
|
||||
|
||||
copy "app.css"
|
||||
copy "moonscript.css"
|
||||
copy "pygments.css"
|
||||
|
@ -12,7 +12,6 @@
|
||||
media="screen"
|
||||
/>
|
||||
<link rel="stylesheet" href="$root/app.css?$generate_date" />
|
||||
<link rel="stylesheet" href="$root/pygments.css?$generate_date" />
|
||||
<link rel="stylesheet" href="$root/moonscript.css?$generate_date" />
|
||||
</head>
|
||||
<body class="bg-white">
|
||||
|
Loading…
x
Reference in New Issue
Block a user