Browse Source

Var rename & coverage improve

pull/82/head
Vitaly Puzrin 10 years ago
parent
commit
0732ac3bd6
  1. 8
      lib/common/utils.js
  2. 4
      test/fixtures/markdown-it/smartquotes.txt
  3. 9
      test/utils.js

8
lib/common/utils.js

@ -72,9 +72,11 @@ function fromCodePoint(c) {
var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])/g;
var NAMED_ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi;
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) {

4
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""
.
<p>“Monitor 21&quot;”</p>
<p>“Monitor 21&quot;” and “Monitor”&quot;</p>
.

9
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);
});
});
});

Loading…
Cancel
Save