summaryrefslogtreecommitdiff
path: root/js/bin
diff options
context:
space:
mode:
Diffstat (limited to 'js/bin')
-rwxr-xr-xjs/bin/commonmark27
1 files changed, 21 insertions, 6 deletions
diff --git a/js/bin/commonmark b/js/bin/commonmark
index f0c427c..8f1210b 100755
--- a/js/bin/commonmark
+++ b/js/bin/commonmark
@@ -2,21 +2,21 @@
"use strict";
var fs = require('fs');
-var util = require('util');
var commonmark = require('../lib/index.js');
-var parser = new commonmark.DocParser();
-var renderer = new commonmark.HtmlRenderer();
var inps = [];
var file;
var files = [];
-var options = { sourcepos: false };
+var options = { sourcepos: false, time: false };
+var format = 'html';
var i;
for (i = 2; i < process.argv.length; i++) {
var arg = process.argv[i];
if (arg === '--ast') {
- renderer = { render: commonmark.ASTRenderer };
+ format = 'ast';
+ } else if (arg === '--time') {
+ options.time = true;
} else if (arg === '--sourcepos') {
options.sourcepos = true;
} else if (/^--/.test(arg)) {
@@ -27,6 +27,16 @@ for (i = 2; i < process.argv.length; i++) {
}
}
+var parser = new commonmark.DocParser(options);
+var renderer;
+
+if (format === 'html') {
+ renderer = new commonmark.HtmlRenderer(options);
+} else if (format === 'ast') {
+ renderer = new commonmark.ASTRenderer(options);
+ renderer.options.colors = true;
+}
+
if (files.length === 0) {
files = ['/dev/stdin'];
}
@@ -36,4 +46,9 @@ for (i = 0; i < files.length; i++) {
inps.push(fs.readFileSync(file, 'utf8'));
}
-process.stdout.write(renderer.render(parser.parse(inps.join('\n')), options));
+var inp = inps.join('\n');
+var doc = parser.parse(inp);
+
+var rendered = renderer.render(doc);
+
+if (!options.time) { process.stdout.write(rendered); } \ No newline at end of file