cmark

My personal build of CMark ✏️

Commit
d77b868584c988483fdb7892ccc5af09c6d99f1c
Parent
0e8c3fc0f2878ad45023dc53d1fbbc53b82b94d2
Author
John MacFarlane <jgm@berkeley.edu>
Date

JS linter improvements.

Diffstat

4 files changed, 12 insertions, 16 deletions

Status File Name N° Changes Insertions Deletions
Modified js/bin/commonmark 15 7 8
Modified js/lib/blocks.js 3 2 1
Modified js/lib/index.js 2 1 1
Modified js/lib/inlines.js 8 2 6
diff --git 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
@@ -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
@@ -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
@@ -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 {