diff options
Diffstat (limited to 'js/bin/commonmark')
-rwxr-xr-x | js/bin/commonmark | 17 |
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')))); |