From 0732ac3bd627ed64d642b326c3363772a3fc04ac Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Thu, 5 Mar 2015 01:59:40 +0300 Subject: [PATCH] Var rename & coverage improve --- lib/common/utils.js | 10 ++++++---- test/fixtures/markdown-it/smartquotes.txt | 4 ++-- test/utils.js | 9 +++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/common/utils.js b/lib/common/utils.js index 0e05b14..9ce5158 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -71,10 +71,12 @@ function fromCodePoint(c) { } -var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])/g; -var NAMED_ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi; +var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])/g; +var ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi; +var UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.source, 'gi'); + var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i; -var UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + NAMED_ENTITY_RE.source, 'gi'); + var entities = require('./entities'); function replaceEntityPattern(match, name) { @@ -97,7 +99,7 @@ function replaceEntityPattern(match, name) { function replaceEntities(str) { if (str.indexOf('&') < 0) { return str; } - return str.replace(NAMED_ENTITY_RE, replaceEntityPattern); + return str.replace(ENTITY_RE, replaceEntityPattern); } function unescapeMd(str) { diff --git a/test/fixtures/markdown-it/smartquotes.txt b/test/fixtures/markdown-it/smartquotes.txt index a072570..394a134 100644 --- a/test/fixtures/markdown-it/smartquotes.txt +++ b/test/fixtures/markdown-it/smartquotes.txt @@ -74,9 +74,9 @@ Should try and find matching quote in this case: Should not touch 'inches' in quotes: . -"Monitor 21"" +"Monitor 21"" and "Monitor"" . -

“Monitor 21"”

+

“Monitor 21"” and “Monitor”"

. diff --git a/test/utils.js b/test/utils.js index 528f30d..60588c1 100644 --- a/test/utils.js +++ b/test/utils.js @@ -82,8 +82,17 @@ describe('Utils', function () { '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('').forEach(function (ch) { assert.strictEqual(isMdAsciiPunct(ch.charCodeAt(0)), true); }); + }); + + it('unescapeMd', function () { + var unescapeMd = require('../lib/common/utils').unescapeMd; + assert.strictEqual(unescapeMd('\\foo'), '\\foo'); + assert.strictEqual(unescapeMd('foo'), 'foo'); + '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('').forEach(function (ch) { + assert.strictEqual(unescapeMd('\\' + ch), ch); + }); }); });