Make WordPress Core

Changeset 55186


Ignore:
Timestamp:
02/02/2023 12:51:02 AM (2 years ago)
Author:
azaozz
Message:

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.

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r55150 r55186  
    194194                        // Renamed to avoid conflict with jQuery hoverIntent.min.js (after minifying).
    195195                        [ WORKING_DIR + 'wp-includes/js/hoverintent-js.min.js' ]: [ './node_modules/hoverintent/dist/hoverintent.min.js' ],
     196
    196197                        [ WORKING_DIR + 'wp-includes/js/imagesloaded.min.js' ]: [ './node_modules/imagesloaded/imagesloaded.pkgd.min.js' ],
    197198                        [ WORKING_DIR + 'wp-includes/js/jquery/jquery.js' ]: [ './node_modules/jquery/dist/jquery.js' ],
     
    200201                        [ WORKING_DIR + 'wp-includes/js/jquery/jquery.color.min.js' ]: [ './node_modules/jquery-color/dist/jquery.color.min.js' ],
    201202                        [ WORKING_DIR + 'wp-includes/js/masonry.min.js' ]: [ './node_modules/masonry-layout/dist/masonry.pkgd.min.js' ],
    202                         [ WORKING_DIR + 'wp-includes/js/twemoji.js' ]: [ './node_modules/twemoji/dist/twemoji.js' ],
    203203                        [ WORKING_DIR + 'wp-includes/js/underscore.js' ]: [ './node_modules/underscore/underscore.js' ],
    204204                    }
  • trunk/package-lock.json

    r55150 r55186  
    1263012630            "dev": true
    1263112631        },
    12632         "fs-extra": {
    12633             "version": "8.1.0",
    12634             "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
    12635             "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
    12636             "requires": {
    12637                 "graceful-fs": "^4.2.0",
    12638                 "jsonfile": "^4.0.0",
    12639                 "universalify": "^0.1.0"
    12640             },
    12641             "dependencies": {
    12642                 "jsonfile": {
    12643                     "version": "4.0.0",
    12644                     "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
    12645                     "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
    12646                     "requires": {
    12647                         "graceful-fs": "^4.1.6"
    12648                     }
    12649                 }
    12650             }
    12651         },
    1265212632        "fs-monkey": {
    1265312633            "version": "1.0.3",
     
    1318513165            "version": "4.2.4",
    1318613166            "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
    13187             "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
     13167            "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==",
     13168            "dev": true
    1318813169        },
    1318913170        "gradient-parser": {
     
    1782017801            "integrity": "sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==",
    1782117802            "dev": true
    17822         },
    17823         "jsonfile": {
    17824             "version": "5.0.0",
    17825             "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-5.0.0.tgz",
    17826             "integrity": "sha512-NQRZ5CRo74MhMMC3/3r5g2k4fjodJ/wh8MxjFbCViWKFjxrnudWSY5vomh+23ZaXzAS7J3fBZIR2dV6WbmfM0w==",
    17827             "requires": {
    17828                 "graceful-fs": "^4.1.6",
    17829                 "universalify": "^0.1.2"
    17830             }
    1783117803        },
    1783217804        "jsprim": {
     
    2551925491            "dev": true
    2552025492        },
    25521         "twemoji": {
    25522             "version": "14.0.2",
    25523             "resolved": "https://registry.npmjs.org/twemoji/-/twemoji-14.0.2.tgz",
    25524             "integrity": "sha512-BzOoXIe1QVdmsUmZ54xbEH+8AgtOKUiG53zO5vVP2iUu6h5u9lN15NcuS6te4OY96qx0H7JK9vjjl9WQbkTRuA==",
    25525             "requires": {
    25526                 "fs-extra": "^8.0.1",
    25527                 "jsonfile": "^5.0.0",
    25528                 "twemoji-parser": "14.0.0",
    25529                 "universalify": "^0.1.2"
    25530             }
    25531         },
    25532         "twemoji-parser": {
    25533             "version": "14.0.0",
    25534             "resolved": "https://registry.npmjs.org/twemoji-parser/-/twemoji-parser-14.0.0.tgz",
    25535             "integrity": "sha512-9DUOTGLOWs0pFWnh1p6NF+C3CkQ96PWmEFwhOVmT3WbecRC+68AIqpsnJXygfkFcp4aXbOp8Dwbhh/HQgvoRxA=="
    25536         },
    2553725493        "type-check": {
    2553825494            "version": "0.4.0",
     
    2569325649            "integrity": "sha1-sxxa6CVIRKOoKBVBzisEuGWnNP8=",
    2569425650            "dev": true
    25695         },
    25696         "universalify": {
    25697             "version": "0.1.2",
    25698             "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
    25699             "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
    2570025651        },
    2570125652        "unpipe": {
  • trunk/package.json

    r55150 r55186  
    154154        "react-dom": "17.0.2",
    155155        "regenerator-runtime": "0.13.9",
    156         "twemoji": "14.0.2",
    157156        "underscore": "1.13.6",
    158157        "whatwg-fetch": "3.6.2",
  • trunk/src/js/_enqueues/wp/emoji.js

    r47122 r55186  
    146146                            }
    147147
    148                             /*
    149                              * If the class name of a non-element node contains 'wp-exclude-emoji' ignore it.
    150                              *
    151                              * Node type 1 is an ELEMENT_NODE.
    152                              */
    153                             if ( ! node || node.nodeType !== 1 ||
    154                                 ( node.className && typeof node.className === 'string' && node.className.indexOf( 'wp-exclude-emoji' ) !== -1 ) ) {
    155 
    156                                 continue;
    157                             }
    158 
    159148                            if ( test( node.textContent ) ) {
    160149                                parse( node );
     
    264253                        twemoji.parentNode.replaceChild( document.createTextNode( twemoji.alt ), twemoji );
    265254                    }
     255                },
     256                doNotParse: function( node ) {
     257                    if (
     258                        node &&
     259                        node.className &&
     260                        typeof node.className === 'string' &&
     261                        node.className.indexOf( 'wp-exclude-emoji' ) !== -1
     262                    ) {
     263                        // Do not parse this node. Emojis will not be replaced in this node and all sub-nodes.
     264                        return true;
     265                    }
     266
     267                    return false;
    266268                }
    267269            };
Note: See TracChangeset for help on using the changeset viewer.