aboutsummaryrefslogtreecommitdiff
path: root/js/bin/commonmark
blob: 1d395e02a2934e57783020a77e00f3b977d300fa (plain)
  1. #!/usr/bin/env node
  2. var fs = require('fs');
  3. var util = require('util');
  4. var commonmark = require('../lib/index.js');
  5. var parser = new commonmark.DocParser();
  6. var renderer;
  7. var inps = [];
  8. var output_ast = false;
  9. var files = [];
  10. if (process.argv[2] === '--ast') {
  11. output_ast = true;
  12. files = process.argv.slice(3);
  13. renderer = { render: function(x) {
  14. return util.inspect(x, null, Infinity) + '\n';
  15. } };
  16. } else {
  17. files = process.argv.slice(2);
  18. renderer = new commonmark.HtmlRenderer();
  19. }
  20. if (files.length === 0) {
  21. files = ['/dev/stdin'];
  22. }
  23. for (var i = 0; i < files.length; i++) {
  24. file = files[i];
  25. inps.push(fs.readFileSync(file, 'utf8'));
  26. }
  27. process.stdout.write(renderer.render(parser.parse(inps.join('\n'))));