summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/bin/commonmark15
-rw-r--r--js/lib/blocks.js3
-rwxr-xr-xjs/lib/index.js2
-rw-r--r--js/lib/inlines.js8
4 files changed, 12 insertions, 16 deletions
diff --git a/js/bin/commonmark b/js/bin/commonmark
index 4fcb09d..f0c427c 100755
--- a/js/bin/commonmark
+++ b/js/bin/commonmark
@@ -10,15 +10,14 @@ var renderer = new commonmark.HtmlRenderer();
var inps = [];
var file;
var files = [];
-var options = { sourcepos: false, };
+var options = { sourcepos: false };
+var i;
-for (var i = 2; i < process.argv.length; i++) {
+for (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') {
+ if (arg === '--ast') {
+ renderer = { render: commonmark.ASTRenderer };
+ } else if (arg === '--sourcepos') {
options.sourcepos = true;
} else if (/^--/.test(arg)) {
process.stderr.write('Unknown option ' + arg + '\n');
@@ -32,7 +31,7 @@ if (files.length === 0) {
files = ['/dev/stdin'];
}
-for (var i = 0; i < files.length; i++) {
+for (i = 0; i < files.length; i++) {
file = files[i];
inps.push(fs.readFileSync(file, 'utf8'));
}
diff --git a/js/lib/blocks.js b/js/lib/blocks.js
index f965fd7..2939afe 100644
--- a/js/lib/blocks.js
+++ b/js/lib/blocks.js
@@ -16,7 +16,7 @@ var isBlank = function(s) {
// Convert tabs to spaces on each line using a 4-space tab stop.
var detabLine = function(text) {
"use strict";
- if (text.indexOf('\0') !== -1) {
+ if (text.indexOf('\u0000') !== -1) {
// replace NUL for security
text = text.replace(/\0/g, '\uFFFD');
}
@@ -637,6 +637,7 @@ var processInlines = function(block) {
};
var Document = function() {
+ "use strict";
var doc = new Node('Document', [[1, 1], [0, 0]]);
doc.string_content = undefined;
doc.strings = [];
diff --git a/js/lib/index.js b/js/lib/index.js
index 8b26946..d0532c6 100755
--- a/js/lib/index.js
+++ b/js/lib/index.js
@@ -14,7 +14,7 @@
var util = require('util');
var renderAST = function(tree) {
- return util.inspect(tree.toAST(), {depth: 20});
+ return util.inspect(tree.toAST(), {depth: 20}) + '\n';
};
module.exports.Node = require('./node');
diff --git a/js/lib/inlines.js b/js/lib/inlines.js
index 405c6c9..0b40dfd 100644
--- a/js/lib/inlines.js
+++ b/js/lib/inlines.js
@@ -6,7 +6,6 @@ var entityToChar = require('./html5-entities.js').entityToChar;
// Constants for character codes:
var C_NEWLINE = 10;
-var C_SPACE = 32;
var C_ASTERISK = 42;
var C_UNDERSCORE = 95;
var C_BACKTICK = 96;
@@ -62,18 +61,15 @@ var reLinkDestination = new RegExp(
var reEscapable = new RegExp(ESCAPABLE);
-var reAllEscapedChar = new RegExp('\\\\(' + ESCAPABLE + ')', 'g');
-
var reEntityHere = new RegExp('^' + ENTITY, 'i');
-var reEntity = new RegExp(ENTITY, 'gi');
-
var reEntityOrEscapedChar = new RegExp('\\\\' + ESCAPABLE + '|' + ENTITY, 'gi');
// Matches a string of non-special characters.
var reMain = /^[^\n`\[\]\\!<&*_]+/m;
var unescapeChar = function(s) {
+ "use strict";
if (s[0] === '\\') {
return s[1];
} else {
@@ -687,7 +683,7 @@ var parseNewline = function(block) {
if (lastc && lastc.t === 'Text') {
var sps = / *$/.exec(lastc.literal)[0].length;
if (sps > 0) {
- lastc.literal = lastc.literal.replace(/ *$/,'');
+ lastc.literal = lastc.literal.replace(/ *$/, '');
}
block.appendChild(new Node(sps >= 2 ? 'Hardbreak' : 'Softbreak'));
} else {