cmark

My personal build of CMark ✏️

Commit
c6d83e713df9864d704e2d12c3f62ff3be8535fd
Parent
ffbca7b85198c2d0efd71b95ef4a1fa693578af0
Author
John MacFarlane <jgm@berkeley.edu>
Date

Factored out normalizeURI into a single function in common.js.

This way we can change it without changing four separate places in the code.

Diffstat

2 files changed, 15 insertions, 7 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/common.js 9 8 1
Modified js/lib/inlines.js 13 7 6
diff --git a/js/lib/common.js b/js/lib/common.js
@@ -27,4 +27,11 @@ var unescapeString = function(s) {
     }
 };
 
-module.exports = { unescapeString: unescapeString };
+var normalizeURI = function(uri) {
+    "use strict";
+    return encodeURI(unescape(uri));
+}
+
+module.exports = { unescapeString: unescapeString,
+                   normalizeURI: normalizeURI
+                 };
diff --git a/js/lib/inlines.js b/js/lib/inlines.js
@@ -1,6 +1,7 @@
 var Node = require('./node');
-var unescapeString = require('./common').unescapeString;
-
+var common = require('./common');
+var normalizeURI = common.normalizeURI;
+var unescapeString = common.unescapeString;
 var fromCodePoint = require('./from-code-point.js');
 var entityToChar = require('./html5-entities.js').entityToChar;
 
@@ -209,7 +210,7 @@ var parseAutolink = function(block) {
     if ((m = this.match(reEmailAutolink))) {
         dest = m.slice(1, -1);
         node = new Node('Link');
-        node.destination = 'mailto:' + encodeURI(unescape(dest));
+        node.destination = normalizeURI('mailto:' + dest);
         node.title = '';
         node.appendChild(text(dest));
         block.appendChild(node);
@@ -217,7 +218,7 @@ var parseAutolink = function(block) {
     } else if ((m = this.match(reAutolink))) {
         dest = m.slice(1, -1);
         node = new Node('Link');
-        node.destination = encodeURI(unescape(dest));
+        node.destination = normalizeURI(dest);
         node.title = '';
         node.appendChild(text(dest));
         block.appendChild(node);
@@ -446,11 +447,11 @@ var parseLinkDestination = function() {
     "use strict";
     var res = this.match(reLinkDestinationBraces);
     if (res) {  // chop off surrounding <..>:
-        return encodeURI(unescape(unescapeString(res.substr(1, res.length - 2))));
+        return normalizeURI(unescapeString(res.substr(1, res.length - 2)));
     } else {
         res = this.match(reLinkDestination);
         if (res !== null) {
-            return encodeURI(unescape(unescapeString(res)));
+            return normalizeURI(unescapeString(res));
         } else {
             return null;
         }