[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> html-entities.js (source)

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/define property getters */
   8  /******/     (() => {
   9  /******/         // define getter functions for harmony exports
  10  /******/         __webpack_require__.d = (exports, definition) => {
  11  /******/             for(var key in definition) {
  12  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14  /******/                 }
  15  /******/             }
  16  /******/         };
  17  /******/     })();
  18  /******/     
  19  /******/     /* webpack/runtime/hasOwnProperty shorthand */
  20  /******/     (() => {
  21  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  22  /******/     })();
  23  /******/     
  24  /******/     /* webpack/runtime/make namespace object */
  25  /******/     (() => {
  26  /******/         // define __esModule on exports
  27  /******/         __webpack_require__.r = (exports) => {
  28  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30  /******/             }
  31  /******/             Object.defineProperty(exports, '__esModule', { value: true });
  32  /******/         };
  33  /******/     })();
  34  /******/     
  35  /************************************************************************/
  36  var __webpack_exports__ = {};
  37  __webpack_require__.r(__webpack_exports__);
  38  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  39  /* harmony export */   decodeEntities: () => (/* binding */ decodeEntities)
  40  /* harmony export */ });
  41  /** @type {HTMLTextAreaElement} */
  42  let _decodeTextArea;
  43  
  44  /**
  45   * Decodes the HTML entities from a given string.
  46   *
  47   * @param {string} html String that contain HTML entities.
  48   *
  49   * @example
  50   * ```js
  51   * const result = decodeEntities( 'á' );
  52   * console.log( result ); // result will be "รก"
  53   * ```
  54   *
  55   * @return {string} The decoded string.
  56   */
  57  function decodeEntities(html) {
  58    // Not a string, or no entities to decode.
  59    if ('string' !== typeof html || -1 === html.indexOf('&')) {
  60      return html;
  61    }
  62  
  63    // Create a textarea for decoding entities, that we can reuse.
  64    if (undefined === _decodeTextArea) {
  65      if (document.implementation && document.implementation.createHTMLDocument) {
  66        _decodeTextArea = document.implementation.createHTMLDocument('').createElement('textarea');
  67      } else {
  68        _decodeTextArea = document.createElement('textarea');
  69      }
  70    }
  71    _decodeTextArea.innerHTML = html;
  72    const decoded = _decodeTextArea.textContent;
  73    _decodeTextArea.innerHTML = '';
  74  
  75    /**
  76     * Cast to string, HTMLTextAreaElement should always have `string` textContent.
  77     *
  78     * > The `textContent` property of the `Node` interface represents the text content of the
  79     * > node and its descendants.
  80     * >
  81     * > Value: A string or `null`
  82     * >
  83     * > * If the node is a `document` or a Doctype, `textContent` returns `null`.
  84     * > * If the node is a CDATA section, comment, processing instruction, or text node,
  85     * >   textContent returns the text inside the node, i.e., the `Node.nodeValue`.
  86     * > * For other node types, `textContent returns the concatenation of the textContent of
  87     * >   every child node, excluding comments and processing instructions. (This is an empty
  88     * >   string if the node has no children.)
  89     *
  90     * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
  91     */
  92    return /** @type {string} */decoded;
  93  }
  94  
  95  (window.wp = window.wp || {}).htmlEntities = __webpack_exports__;
  96  /******/ })()
  97  ;


Generated : Tue Mar 19 08:20:01 2024 Cross-referenced by PHPXref