summaryrefslogtreecommitdiff
path: root/js/bin/commonmark
blob: 1d395e02a2934e57783020a77e00f3b977d300fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env node
var fs = require('fs');
var util = require('util');
var commonmark = require('../lib/index.js');

var parser   = new commonmark.DocParser();
var renderer;
var inps = [];

var output_ast = false;
var files = [];

if (process.argv[2] === '--ast') {
  output_ast = true;
  files = process.argv.slice(3);
  renderer = { render: function(x) {
                          return util.inspect(x, null, Infinity) + '\n';
                        } };
} else {
  files = process.argv.slice(2);
  renderer = new commonmark.HtmlRenderer();
}

if (files.length === 0) {
  files = ['/dev/stdin'];
}

for (var i = 0; i < files.length; i++) {
  file = files[i];
  inps.push(fs.readFileSync(file, 'utf8'));
}

process.stdout.write(renderer.render(parser.parse(inps.join('\n'))));