aboutsummaryrefslogtreecommitdiff
path: root/js/bin/commonmark
blob: 22ebd62506faa78dd8b020d3cc4818dbfb083a92 (plain)
  1. #!/usr/bin/env node
  2. "use strict";
  3. var fs = require('fs');
  4. var commonmark = require('../lib/index.js');
  5. var parser = new commonmark.DocParser();
  6. var renderer = new commonmark.HtmlRenderer();
  7. var inps = [];
  8. var file;
  9. var files = [];
  10. var options = { sourcepos: false };
  11. var i;
  12. for (i = 2; i < process.argv.length; i++) {
  13. var arg = process.argv[i];
  14. if (arg === '--ast') {
  15. renderer = { render: commonmark.ASTRenderer };
  16. } else if (arg === '--sourcepos') {
  17. options.sourcepos = true;
  18. } else if (/^--/.test(arg)) {
  19. process.stderr.write('Unknown option ' + arg + '\n');
  20. process.exit(1);
  21. } else {
  22. files.push(arg);
  23. }
  24. }
  25. if (files.length === 0) {
  26. files = ['/dev/stdin'];
  27. }
  28. for (i = 0; i < files.length; i++) {
  29. file = files[i];
  30. inps.push(fs.readFileSync(file, 'utf8'));
  31. }
  32. process.stdout.write(renderer.render(parser.parse(inps.join('\n')), options));