blob: 4fcb09d17759e2438e0db0d141025afe9cc84937 (
plain)
- #!/usr/bin/env node
- "use strict";
- var fs = require('fs');
- var util = require('util');
- 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, };
- for (var i = 2; i < process.argv.length; i++) {
- var arg = process.argv[i];
- if (arg == '--ast') {
- renderer = { render: function(x) {
- return util.inspect(x.toAST(), null, 20, true) + '\n';
- } };
- } else if (arg == '--sourcepos') {
- options.sourcepos = true;
- } else if (/^--/.test(arg)) {
- process.stderr.write('Unknown option ' + arg + '\n');
- process.exit(1);
- } else {
- files.push(arg);
- }
- }
- 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')), options));
|