cmark

My personal build of CMark ✏️

Commit
efff87ae0da05a94e8416ff090fdfcd5634c36a7
Parent
d91e106123f0853e6380b5d7c8d856365c9b331a
Author
John MacFarlane <jgm@berkeley.edu>
Date

Add unescapeString as method of InlineParser.

Diffstat

2 files changed, 10 insertions, 9 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/blocks.js 7 4 3
Modified js/lib/inlines.js 12 6 6
diff --git a/js/lib/blocks.js b/js/lib/blocks.js
@@ -2,7 +2,8 @@ var C_GREATERTHAN = 62;
 var C_SPACE = 32;
 var C_OPEN_BRACKET = 91;
 
-var _inlines = require('./inlines');
+var InlineParser = require('./inlines');
+var unescapeString = new InlineParser().unescapeString;
 
 // Returns true if string contains only space characters.
 var isBlank = function(s) {
@@ -566,7 +567,7 @@ var finalize = function(block, line_number) {
 
     case 'FencedCode':
         // first line becomes info string
-        block.info = _inlines.unescapeEntBS(block.strings[0].trim());
+        block.info = unescapeString(block.strings[0].trim());
         if (block.strings.length == 1) {
             block.string_content = '';
         } else {
@@ -658,7 +659,7 @@ function DocParser(){
         doc: makeBlock('Document', 1, 1),
         tip: this.doc,
         refmap: {},
-        inlineParser: new _inlines.InlineParser(),
+        inlineParser: new InlineParser(),
         breakOutOfLists: breakOutOfLists,
         addLine: addLine,
         addChild: addChild,
diff --git a/js/lib/inlines.js b/js/lib/inlines.js
@@ -76,7 +76,7 @@ var reEntity = new RegExp(ENTITY, 'gi');
 var reMain = /^(?:[_*`\n]+|[\[\]\\!<&*_]|(?: *[^\n `\[\]\\!<&*_]+)+|[ \n]+)/m;
 
 // Replace entities and backslash escapes with literal characters.
-var unescapeEntBS = function(s) {
+var unescapeString = function(s) {
     return s.replace(reAllEscapedChar, '$1')
             .replace(reEntity, entityToChar);
 };
@@ -357,7 +357,7 @@ var parseLinkTitle = function() {
     var title = this.match(reLinkTitle);
     if (title) {
         // chop off quotes from title and unescape:
-        return unescapeEntBS(title.substr(1, title.length - 2));
+        return unescapeString(title.substr(1, title.length - 2));
     } else {
         return null;
     }
@@ -368,11 +368,11 @@ var parseLinkTitle = function() {
 var parseLinkDestination = function() {
     var res = this.match(reLinkDestinationBraces);
     if (res) {  // chop off surrounding <..>:
-        return encodeURI(unescape(unescapeEntBS(res.substr(1, res.length - 2))));
+        return encodeURI(unescape(unescapeString(res.substr(1, res.length - 2))));
     } else {
         res = this.match(reLinkDestination);
         if (res !== null) {
-            return encodeURI(unescape(unescapeEntBS(res)));
+            return encodeURI(unescape(unescapeString(res)));
         } else {
             return null;
         }
@@ -715,6 +715,7 @@ function InlineParser(){
         match: match,
         peek: peek,
         spnl: spnl,
+        unescapeString: unescapeString,
         parseBackticks: parseBackticks,
         parseBackslash: parseBackslash,
         parseAutolink: parseAutolink,
@@ -735,5 +736,4 @@ function InlineParser(){
     };
 }
 
-module.exports.unescapeEntBS = unescapeEntBS;
-module.exports.InlineParser = InlineParser;
+module.exports = InlineParser;