summaryrefslogtreecommitdiff
path: root/js/bin/commonmark
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-10 17:17:09 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-10 17:17:09 -0800
commit2fe4743a1303ca5dcba4018519a044e9de8e11db (patch)
treee5ce227f23b113c3bc2b8bbb9f819d15618cec7c /js/bin/commonmark
parent0f3d82b846fb70835a059542405e849a59fa2e0a (diff)
Made 'options' a parameter of the renderer constructors...
as opposed to the 'render' function. Added a 'colors' parameter for the ast renderer.
Diffstat (limited to 'js/bin/commonmark')
-rwxr-xr-xjs/bin/commonmark17
1 files changed, 13 insertions, 4 deletions
diff --git a/js/bin/commonmark b/js/bin/commonmark
index 22ebd62..e48e05e 100755
--- a/js/bin/commonmark
+++ b/js/bin/commonmark
@@ -4,18 +4,17 @@
var fs = require('fs');
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 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 === '--sourcepos') {
options.sourcepos = true;
} else if (/^--/.test(arg)) {
@@ -26,6 +25,16 @@ for (i = 2; i < process.argv.length; i++) {
}
}
+var parser = new commonmark.DocParser();
+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'];
}
@@ -35,4 +44,4 @@ for (i = 0; i < files.length; i++) {
inps.push(fs.readFileSync(file, 'utf8'));
}
-process.stdout.write(renderer.render(parser.parse(inps.join('\n')), options));
+process.stdout.write(renderer.render(parser.parse(inps.join('\n'))));