56 lines
1.5 KiB
Plaintext
56 lines
1.5 KiB
Plaintext
Path = require "sitegen.path"
|
|
|
|
needs_shell_escape = (str) -> not not str\match "[^%w_-]"
|
|
shell_escape = (str) -> str\gsub "'", "''"
|
|
|
|
_prepare_command = (cmd, ...) ->
|
|
args = for x in *{...}
|
|
if needs_shell_escape x then "'#{shell_escape x}'" else x
|
|
|
|
args = table.concat args, " "
|
|
"#{cmd} #{args}"
|
|
|
|
write_exec = (input, cmd, ...) ->
|
|
handle = io.popen _prepare_command(cmd, ...), "w"
|
|
with handle\write input
|
|
handle\close!
|
|
|
|
convert = =>
|
|
(md_source) ->
|
|
filename = os.tmpname!
|
|
write_exec md_source, @cmd, filename
|
|
a = Path.read_file filename
|
|
require("moon").p a
|
|
a
|
|
|
|
-- fname = os.tmpname!
|
|
-- with io.open fname, "w"
|
|
-- \write md_source
|
|
-- \close!
|
|
--
|
|
-- p = io.popen (@cmd)\format lang, fname
|
|
-- out = p\read"*a"
|
|
-- out
|
|
|
|
-- config command like this in site.moon:
|
|
-- require("renderers.markdown").cmd = "pandoc --mathjax >"
|
|
class PandocRenderer extends require "sitegen.renderers.markdown"
|
|
unescape_cosmo = @unescape_cosmo
|
|
escape_cosmo = @escape_cosmo
|
|
pandoc = convert @
|
|
|
|
-- cmd: "pandoc >"
|
|
cmd: "pandoc --mathjax --lua-filter pygments.lua >"
|
|
-- cmd: "pygmentize -f html -l %s %s"
|
|
-- cmd: "pygmentize -f html -l %s %s -x"
|
|
-- cmd: "pygmentize -f html -l moonscript.py test.moon -x -o lexer-test.html"
|
|
|
|
render: (page, md_source) =>
|
|
md_source = page\pipe "renderer.markdown.pre_render", md_source
|
|
md_source, escapes = escape_cosmo md_source
|
|
|
|
html_source = assert pandoc md_source
|
|
html_source = unescape_cosmo html_source, escapes
|
|
|
|
super page, html_source
|