80 lines
1.9 KiB
Plaintext
80 lines
1.9 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!
|
|
|
|
get_pandoc = (md_source) =>
|
|
markup_filename = os.tmpname!
|
|
write_exec md_source, @@cmd, markup_filename
|
|
Path.read_file markup_filename
|
|
|
|
-- blah = (...) => pandoc, @, ...
|
|
|
|
get_thing = (md_source) =>
|
|
markup_filename = os.tmpname!
|
|
write_exec md_source, @cmd, markup_filename
|
|
Path.read_file markup_filename
|
|
|
|
test = =>
|
|
require("moon").p @cmd
|
|
-- print thing
|
|
|
|
-- blah = ->
|
|
-- require("moon").p @cmd
|
|
|
|
oh = ->
|
|
require("moon").p @
|
|
|
|
class PandocRenderer extends require "sitegen.renderers.markdown"
|
|
unescape_cosmo = @unescape_cosmo
|
|
escape_cosmo = @escape_cosmo
|
|
-- pandoc = (...) -> get_pandoc @, ...
|
|
pandoc: get_pandoc
|
|
-- require("moon").p @cmd
|
|
-- blah = ->
|
|
-- require("moon").p @cmd
|
|
-- pandoc = (md_source) ->
|
|
-- markup_filename = os.tmpname!
|
|
-- write_exec md_source, @cmd, markup_filename
|
|
-- Path.read_file markup_filename
|
|
|
|
-- blah = test @
|
|
-- blah = (words) ->
|
|
-- words
|
|
|
|
-- blah = (words) -> test @
|
|
blah = (md_source) -> get_thing @, md_source
|
|
|
|
@cmd: "pandoc >"
|
|
|
|
-- test: =>
|
|
-- "test"
|
|
|
|
render: (page, md_source) =>
|
|
-- blah = oh
|
|
|
|
-- print @@cmd
|
|
-- blah!
|
|
-- require("moon").p blah "these"
|
|
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 = assert blah md_source
|
|
-- html_source = assert pandoc md_source
|
|
html_source = unescape_cosmo html_source, escapes
|
|
|
|
super page, html_source
|