Skip to content

Commit

Permalink
Convert subset of HTML entities
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Sep 14, 2021
1 parent 12f0370 commit 056b585
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/blocks/src/api/matchers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { decodeEntities } from '@wordpress/html-entities';

/**
* External dependencies
*/
Expand All @@ -14,6 +9,20 @@ export { attr, prop, text, query } from 'hpq';
export { matcher as node } from './node';
export { matcher as children } from './children';

function replaceInnerHTMLEntities( innerHTML ) {
const entityRegEx = /&(amp|lt|gt);/g;

// This subset of chars are returned as HTML entities from Element.innerHTML
const lookUp = {
amp: '&',
lt: '<',
gt: '>',
};

// Replace entity with text equivalent.
return innerHTML.replace( entityRegEx, ( match, p1 ) => lookUp[ p1 ] );
}

export function html( selector, multilineTag ) {
return ( domNode ) => {
let match = domNode;
Expand Down Expand Up @@ -43,6 +52,6 @@ export function html( selector, multilineTag ) {
return value;
}

return decodeEntities( match.innerHTML );
return replaceInnerHTMLEntities( match.innerHTML );
};
}

0 comments on commit 056b585

Please sign in to comment.