markdown_it.lua

Mon, 06 Jul 2020 13:01:18 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 06 Jul 2020 13:01:18 -0500
changeset 28
9b75d0f5e042
parent 21
3c71c525cec2
child 30
3ac53da03439
permissions
-rw-r--r--

Use @neilsustc/markdown-it-katex instead of markdown-it-katex.
The latter is broken

21
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 local markdown_it={}
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 local io = require('io')
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 local os = require('os')
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6 function markdown_it.markdown(str, env)
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7 -- Lua doesn't have bidirectional pipes without the posix library.
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 -- Keep things and compatible and use temporary files.
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 tmpname = os.tmpname()
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 file = io.open(tmpname, 'w')
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 file:write(str)
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 cmd = string.format("node '%s/markdown_it.js' '%s'",
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 env.paths.lgen_location,
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 tmpname)
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 io.stdout:write('Executing ' .. cmd .. '\n')
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 h = io.popen(cmd, 'r')
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 result = h:read("*a")
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18 h:close()
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 file:close()
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 return result
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 end
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22
3c71c525cec2 Use markdown-it as default markdown parser.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23 return markdown_it

mercurial