blob: 6570ef61b346f5a58d30b240d7ff7f694cdea420 (
plain)
- #!/usr/bin/env node
- "use strict";
- var fs = require('fs');
- var commonmark = require('../lib/index.js');
- var inps = [];
- var file;
- var files = [];
- var options = { sourcepos: false, time: false };
- var format = 'html';
- var i;
- for (i = 2; i < process.argv.length; i++) {
- var arg = process.argv[i];
- if (arg === '--ast') {
- format = 'ast';
- } else if (arg === '--xml') {
- format = 'xml';
- } else if (arg === '--time') {
- options.time = true;
- } 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);
- }
- }
- var parser = new commonmark.DocParser(options);
- var renderer;
- if (format === 'html') {
- renderer = new commonmark.HtmlRenderer(options);
- } else if (format === 'xml') {
- renderer = new commonmark.XMLRenderer(options);
- } else if (format === 'ast') {
- renderer = new commonmark.ASTRenderer(options);
- renderer.options.colors = true;
- }
- if (files.length === 0) {
- files = ['/dev/stdin'];
- }
- for (i = 0; i < files.length; i++) {
- file = files[i];
- inps.push(fs.readFileSync(file, 'utf8'));
- }
- var inp = inps.join('\n');
- var doc = parser.parse(inp);
- var rendered = renderer.render(doc);
- if (!options.time) { process.stdout.write(rendered); }
|