aboutsummaryrefslogtreecommitdiff
path: root/js/bin/commonmark
blob: 3c222f8664ed6a048dc2571e29f94f50debac847 (plain)
  1. #!/usr/bin/env node
  2. "use strict";
  3. var fs = require('fs');
  4. var util = require('util');
  5. var commonmark = require('../lib/index.js');
  6. var parser = new commonmark.DocParser();
  7. var renderer;
  8. var inps = [];
  9. var file;
  10. var files = [];
  11. if (process.argv[2] === '--ast') {
  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'))));