Sun, 06 Sep 2020 22:29:08 +0300
enable markdown-it-checkbox
local markdown_it={} local io = require('io') local os = require('os') local path = require('mypath') local lfs = require('lfs') function markdown_it.katex_config(env) katex_config = path.join(env.paths.tmpl, "katex_config.json") if lfs.attributes(katex_config) then return katex_config else return nil end end function markdown_it.markdown(str, env) -- Lua doesn't have bidirectional pipes without the posix library. -- Keep things and compatible and use temporary files. tmpname = os.tmpname() file = io.open(tmpname, 'w') file:write(str) cmd = string.format("node '%s/markdown_it.js' '%s'", env.paths.lgen_location, tmpname) -- Provide TEMPLATE_PATH/katex_config.json if it exists katex_config = markdown_it.katex_config(env) if katex_config then cmd = cmd .. " '" .. katex_config .. "'" end io.stdout:write('Executing ' .. cmd .. '\n') h = io.popen(cmd, 'r') result = h:read("*a") h:close() file:close() return result end function markdown_it.add_deps(deps, env) katex_config = markdown_it.katex_config(env) if katex_config then table.insert(deps, katex_config) end end return markdown_it