Emoji: Always skip nodes with the wp-exclude-emoji CSS class.

Patches twemoji.js to add support for a `doNotParse()` callback. Uses that callback to always exclude emojis in HTML elements with the above class.

Props: dd32, peterwilsoncc, azaozz.
Fixes #52219.

git-svn-id: https://develop.svn.wordpress.org/trunk@55186 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2023-02-02 00:51:02 +00:00
parent 6b4b2eb60f
commit 4dd9160d8e
5 changed files with 605 additions and 64 deletions

589
src/js/_enqueues/vendor/twemoji.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -145,17 +145,6 @@
node = node.parentNode;
}
/*
* If the class name of a non-element node contains 'wp-exclude-emoji' ignore it.
*
* Node type 1 is an ELEMENT_NODE.
*/
if ( ! node || node.nodeType !== 1 ||
( node.className && typeof node.className === 'string' && node.className.indexOf( 'wp-exclude-emoji' ) !== -1 ) ) {
continue;
}
if ( test( node.textContent ) ) {
parse( node );
}
@@ -263,6 +252,19 @@
this.setAttribute( 'data-error', 'load-failed' );
twemoji.parentNode.replaceChild( document.createTextNode( twemoji.alt ), twemoji );
}
},
doNotParse: function( node ) {
if (
node &&
node.className &&
typeof node.className === 'string' &&
node.className.indexOf( 'wp-exclude-emoji' ) !== -1
) {
// Do not parse this node. Emojis will not be replaced in this node and all sub-nodes.
return true;
}
return false;
}
};