local core = require "core" local command = require "core.command" local keymap = require "core.keymap" local html = [[ ${title} ]] command.add("core.docview", { ["ghmarkdown:show-preview"] = function() local dv = core.active_view local content = dv.doc:get_text(1, 1, math.huge, math.huge) local esc = { ['"'] = '\\"', ["\n"] = '\\n' } local text = html:gsub("${(.-)}", { title = dv:get_name(), content = content:gsub(".", esc) }) local htmlfile = ".lite_ghmarkdown_" .. os.tmpname():gsub("%W", "") .. ".html" local fp = io.open(htmlfile, "w") fp:write(text) fp:close() core.log("Opening markdown preview for \"%s\"", dv:get_name()) local path = system.absolute_path(".") .. "/" .. htmlfile if PLATFORM == "Windows" then system.exec("start " .. path) else system.exec(string.format("xdg-open %q", path)) end core.add_thread(function() coroutine.yield(5) os.remove(htmlfile) end) end }) keymap.add { ["ctrl+shift+m"] = "ghmarkdown:show-preview" }