Browse Source

chore: Update entities dependency (#901)

* Update entities package + usage

* Apply custom digital entity logic before entities decode
pull/972/head
Matt Cowley 1 year ago
committed by GitHub
parent
commit
8470eb6706
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      lib/common/entities.js
  2. 15
      lib/common/utils.js
  3. 10
      lib/rules_inline/entity.js
  4. 2
      package.json

6
lib/common/entities.js

@ -1,6 +0,0 @@
// HTML5 entities map: { name -> utf16string }
//
'use strict';
/*eslint quotes:0*/
module.exports = require('entities/lib/maps/entities.json');

15
lib/common/utils.js

@ -77,14 +77,10 @@ var UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.source,
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 entities = require('./entities'); var decodeHTML = require('entities').decodeHTML;
function replaceEntityPattern(match, name) { function replaceEntityPattern(match, name) {
var code; var decoded, code;
if (has(entities, name)) {
return entities[name];
}
if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) {
code = name[1].toLowerCase() === 'x' ? code = name[1].toLowerCase() === 'x' ?
@ -93,6 +89,13 @@ function replaceEntityPattern(match, name) {
if (isValidEntityCode(code)) { if (isValidEntityCode(code)) {
return fromCodePoint(code); return fromCodePoint(code);
} }
return match;
}
decoded = decodeHTML(match);
if (decoded !== match) {
return decoded;
} }
return match; return match;

10
lib/rules_inline/entity.js

@ -2,8 +2,7 @@
'use strict'; 'use strict';
var entities = require('../common/entities'); var decodeHTML = require('entities').decodeHTML;
var has = require('../common/utils').has;
var isValidEntityCode = require('../common/utils').isValidEntityCode; var isValidEntityCode = require('../common/utils').isValidEntityCode;
var fromCodePoint = require('../common/utils').fromCodePoint; var fromCodePoint = require('../common/utils').fromCodePoint;
@ -13,7 +12,7 @@ var NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i;
module.exports = function entity(state, silent) { module.exports = function entity(state, silent) {
var ch, code, match, token, pos = state.pos, max = state.posMax; var ch, code, match, decoded, token, pos = state.pos, max = state.posMax;
if (state.src.charCodeAt(pos) !== 0x26/* & */) return false; if (state.src.charCodeAt(pos) !== 0x26/* & */) return false;
@ -38,10 +37,11 @@ module.exports = function entity(state, silent) {
} else { } else {
match = state.src.slice(pos).match(NAMED_RE); match = state.src.slice(pos).match(NAMED_RE);
if (match) { if (match) {
if (has(entities, match[1])) { decoded = decodeHTML(match[0]);
if (decoded !== match[0]) {
if (!silent) { if (!silent) {
token = state.push('text_special', '', 0); token = state.push('text_special', '', 0);
token.content = entities[match[1]]; token.content = decoded;
token.markup = match[0]; token.markup = match[0];
token.info = 'entity'; token.info = 'entity';
} }

2
package.json

@ -38,7 +38,7 @@
], ],
"dependencies": { "dependencies": {
"argparse": "^2.0.1", "argparse": "^2.0.1",
"entities": "~3.0.1", "entities": "^4.4.0",
"linkify-it": "^4.0.1", "linkify-it": "^4.0.1",
"mdurl": "^1.0.1", "mdurl": "^1.0.1",
"uc.micro": "^1.0.5" "uc.micro": "^1.0.5"

Loading…
Cancel
Save