aboutsummaryrefslogtreecommitdiff
path: root/js/bin
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-09 19:10:24 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-09 19:10:24 -0800
commita1bc760fef3ae9e98f039fa50f31fc2d5eb877a2 (patch)
tree31112fdecb5e60ccc9c318391e30f551d78522c9 /js/bin
parent7bfb5dd6915fd455e93086fc2b546802bdd77027 (diff)
Added options to render, implemented sourcepos option.
This adds data-sourcepos attributes on block-level tags in the HTML output. Also added `--sourcepos` command-line option to `js/bin/commonmark`.
Diffstat (limited to 'js/bin')
-rwxr-xr-xjs/bin/commonmark27
1 files changed, 17 insertions, 10 deletions
diff --git a/js/bin/commonmark b/js/bin/commonmark
index ac53e6e..72ad344 100755
--- a/js/bin/commonmark
+++ b/js/bin/commonmark
@@ -6,19 +6,26 @@ var util = require('util');
var commonmark = require('../lib/index.js');
var parser = new commonmark.DocParser();
-var renderer;
+var renderer = new commonmark.HtmlRenderer();
var inps = [];
var file;
var files = [];
+var options = { sourcepos: false, };
-if (process.argv[2] === '--ast') {
- files = process.argv.slice(3);
- renderer = { render: function(x) {
- return util.inspect(x.toAST(), null, Infinity, true) + '\n';
- } };
-} else {
- files = process.argv.slice(2);
- renderer = new commonmark.HtmlRenderer();
+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, Infinity, 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) {
@@ -30,4 +37,4 @@ for (var i = 0; i < files.length; i++) {
inps.push(fs.readFileSync(file, 'utf8'));
}
-process.stdout.write(renderer.render(parser.parse(inps.join('\n'))));
+process.stdout.write(renderer.render(parser.parse(inps.join('\n')), options));