Differences From
Artifact [ad6ab18d31]:
1 +-- [ʞ] cli.lua
2 +-- ~ lexi hale <lexi@hale.su>
3 +-- 🄯 AGPLv3
4 +-- ? simple command line driver for the cortav library
1 5 local ct = require 'cortav'
2 6 local ss = require 'sirsem'
3 7
4 8 local default_mode = {
5 9 ['render:format'] = 'html';
6 10 ['html:gen-styles'] = true;
11 + ['groff:color'] = true;
7 12 }
8 13
9 14 local function
10 15 main(input, output, log, mode, suggestions, vars, extrule)
11 16 local doc = ct.parse(input.stream, input.src, mode, function(c)
12 17 c.doc.ext = extrule
13 18 end)
................................................................................
33 38 local render_opts = ss.kmap(function(k,v)
34 39 return k:sub(2+#mode['render:format'])
35 40 end, ss.kfilter(mode, function(m)
36 41 return ss.str.begins(m, mode['render:format']..':')
37 42 end))
38 43
39 44 doc.vars = vars
40 -
41 - -- this is kind of gross but the context object belongs to the parser,
42 - -- not the renderer, so that's not a suitable place for this information
43 - doc.stage = {
44 - kind = 'render';
45 - format = mode['render:format'];
46 - mode = mode;
47 - suggestions = suggestions;
48 - }
49 45
50 - output:write(ct.render[mode['render:format']](doc, render_opts))
46 + output:write(ct.render[mode['render:format']](
47 + doc, render_opts, function(stage)
48 + stage.mode = mode
49 + end))
51 50 return 0
52 51 end
53 52
54 53 local inp,outp,log = io.stdin, io.stdout, io.stderr
55 54
56 55 local function entry_cli()
57 56 local suggestions, vars, input = default_mode, {}, {