|
@ -41,15 +41,6 @@ function arrayReplaceAt(src, pos, newElements) { |
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])/g; |
|
|
|
|
|
|
|
|
|
|
|
function unescapeMd(str) { |
|
|
|
|
|
if (str.indexOf('\\') < 0) { return str; } |
|
|
|
|
|
return str.replace(UNESCAPE_MD_RE, '$1'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
function isValidEntityCode(c) { |
|
|
function isValidEntityCode(c) { |
|
|
/*eslint no-bitwise:0*/ |
|
|
/*eslint no-bitwise:0*/ |
|
|
// broken sequence
|
|
|
// broken sequence
|
|
@ -79,8 +70,11 @@ function fromCodePoint(c) { |
|
|
return String.fromCharCode(c); |
|
|
return String.fromCharCode(c); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var NAMED_ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi; |
|
|
|
|
|
|
|
|
var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])/g; |
|
|
|
|
|
var NAMED_ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi; |
|
|
var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i; |
|
|
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'); |
|
|
var entities = require('./entities'); |
|
|
|
|
|
|
|
|
function replaceEntityPattern(match, name) { |
|
|
function replaceEntityPattern(match, name) { |
|
@ -106,6 +100,20 @@ function replaceEntities(str) { |
|
|
return str.replace(NAMED_ENTITY_RE, replaceEntityPattern); |
|
|
return str.replace(NAMED_ENTITY_RE, replaceEntityPattern); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function unescapeMd(str) { |
|
|
|
|
|
if (str.indexOf('\\') < 0) { return str; } |
|
|
|
|
|
return str.replace(UNESCAPE_MD_RE, '$1'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function unescapeAll(str) { |
|
|
|
|
|
if (str.indexOf('\\') < 0 && str.indexOf('&') < 0) { return str; } |
|
|
|
|
|
|
|
|
|
|
|
return str.replace(UNESCAPE_ALL_RE, function(match, escaped, entity) { |
|
|
|
|
|
if (escaped) { return escaped; } |
|
|
|
|
|
return replaceEntityPattern(match, entity); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
var HTML_ESCAPE_TEST_RE = /[&<>"]/; |
|
|
var HTML_ESCAPE_TEST_RE = /[&<>"]/; |
|
@ -142,7 +150,7 @@ var encode = require('mdurl/encode'); |
|
|
// - (?) punicode for domain mame (but encodeURI seems to work in real world)
|
|
|
// - (?) punicode for domain mame (but encodeURI seems to work in real world)
|
|
|
//
|
|
|
//
|
|
|
function normalizeLink(url) { |
|
|
function normalizeLink(url) { |
|
|
return encode(replaceEntities(url)); |
|
|
return encode(url); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
@ -248,6 +256,7 @@ exports.assign = assign; |
|
|
exports.isString = isString; |
|
|
exports.isString = isString; |
|
|
exports.has = has; |
|
|
exports.has = has; |
|
|
exports.unescapeMd = unescapeMd; |
|
|
exports.unescapeMd = unescapeMd; |
|
|
|
|
|
exports.unescapeAll = unescapeAll; |
|
|
exports.isValidEntityCode = isValidEntityCode; |
|
|
exports.isValidEntityCode = isValidEntityCode; |
|
|
exports.fromCodePoint = fromCodePoint; |
|
|
exports.fromCodePoint = fromCodePoint; |
|
|
exports.replaceEntities = replaceEntities; |
|
|
exports.replaceEntities = replaceEntities; |
|
|