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).

16
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 local pandoc={}
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 local io = require('io')
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 local os = require('os')
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6 function pandoc.pandoc(str)
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7 -- Lua doesn't have bidirectional pipes without the posix library.
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 -- Keep things and compatible and use temporary files.
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 tmpname = os.tmpname()
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 file = io.open(tmpname, 'w')
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 file:write(str)
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 cmd = 'pandoc --from=markdown --to=html "' .. tmpname .. '"'
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 io.stdout:write('Executing ' .. cmd .. '\n')
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 h = io.popen(cmd, 'r')
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 result = h:read("*a")
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 h:close()
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 file:close()
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18 return result
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 end
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20
e377590e9b19 Support Pandoc rendering
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 return pandoc

mercurial