pandoc.lua

Sun, 19 Jul 2020 11:12:54 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 19 Jul 2020 11:12:54 -0500
changeset 32
cef0a28afae0
parent 16
e377590e9b19
child 39
5fc5f93a8cad
permissions
-rw-r--r--

Replace local links to .md by corresponding .html on build (markdown-it only).

local pandoc={}

local io = require('io')
local os = require('os')

function pandoc.pandoc(str)
    -- 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 = 'pandoc --from=markdown --to=html "' .. tmpname .. '"'
    io.stdout:write('Executing ' .. cmd .. '\n')
    h = io.popen(cmd, 'r')
    result = h:read("*a")
    h:close()
    file:close()
    return result
end

return pandoc

mercurial