diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-10-24 21:19:17 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-10-24 21:19:17 -0700 |
commit | 92fb304b7307f77a5c22e834631ef1952e5be099 (patch) | |
tree | 567d99cce51faab087482f66b1d37e3ba3f86aa9 /js/bin/commonmark | |
parent | 80b09d9552e57011c849fc305553501611b3079d (diff) |
Rename js/bin/markdown -> js/bin/commonmark.
Diffstat (limited to 'js/bin/commonmark')
-rwxr-xr-x | js/bin/commonmark | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/js/bin/commonmark b/js/bin/commonmark new file mode 100755 index 0000000..1d395e0 --- /dev/null +++ b/js/bin/commonmark @@ -0,0 +1,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')))); |