wp/wp-includes/js/dist/autop.js
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     1 this["wp"] = this["wp"] || {}; this["wp"]["autop"] =
     1 /******/ (function() { // webpackBootstrap
     2 /******/ (function(modules) { // webpackBootstrap
     2 /******/ 	"use strict";
     3 /******/ 	// The module cache
     3 /******/ 	// The require scope
     4 /******/ 	var installedModules = {};
     4 /******/ 	var __webpack_require__ = {};
     5 /******/
     5 /******/ 	
     6 /******/ 	// The require function
     6 /************************************************************************/
     7 /******/ 	function __webpack_require__(moduleId) {
     7 /******/ 	/* webpack/runtime/define property getters */
     8 /******/
     8 /******/ 	!function() {
     9 /******/ 		// Check if module is in cache
     9 /******/ 		// define getter functions for harmony exports
    10 /******/ 		if(installedModules[moduleId]) {
    10 /******/ 		__webpack_require__.d = function(exports, definition) {
    11 /******/ 			return installedModules[moduleId].exports;
    11 /******/ 			for(var key in definition) {
    12 /******/ 		}
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    13 /******/ 		// Create a new module (and put it into the cache)
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    14 /******/ 		var module = installedModules[moduleId] = {
    14 /******/ 				}
    15 /******/ 			i: moduleId,
    15 /******/ 			}
    16 /******/ 			l: false,
       
    17 /******/ 			exports: {}
       
    18 /******/ 		};
    16 /******/ 		};
    19 /******/
    17 /******/ 	}();
    20 /******/ 		// Execute the module function
    18 /******/ 	
    21 /******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    22 /******/
    20 /******/ 	!function() {
    23 /******/ 		// Flag the module as loaded
    21 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
    24 /******/ 		module.l = true;
    22 /******/ 	}();
    25 /******/
    23 /******/ 	
    26 /******/ 		// Return the exports of the module
    24 /******/ 	/* webpack/runtime/make namespace object */
    27 /******/ 		return module.exports;
    25 /******/ 	!function() {
    28 /******/ 	}
    26 /******/ 		// define __esModule on exports
    29 /******/
    27 /******/ 		__webpack_require__.r = function(exports) {
    30 /******/
    28 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    31 /******/ 	// expose the modules object (__webpack_modules__)
    29 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    32 /******/ 	__webpack_require__.m = modules;
    30 /******/ 			}
    33 /******/
    31 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    34 /******/ 	// expose the module cache
    32 /******/ 		};
    35 /******/ 	__webpack_require__.c = installedModules;
    33 /******/ 	}();
    36 /******/
    34 /******/ 	
    37 /******/ 	// define getter function for harmony exports
       
    38 /******/ 	__webpack_require__.d = function(exports, name, getter) {
       
    39 /******/ 		if(!__webpack_require__.o(exports, name)) {
       
    40 /******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
       
    41 /******/ 		}
       
    42 /******/ 	};
       
    43 /******/
       
    44 /******/ 	// define __esModule on exports
       
    45 /******/ 	__webpack_require__.r = function(exports) {
       
    46 /******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
       
    47 /******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
       
    48 /******/ 		}
       
    49 /******/ 		Object.defineProperty(exports, '__esModule', { value: true });
       
    50 /******/ 	};
       
    51 /******/
       
    52 /******/ 	// create a fake namespace object
       
    53 /******/ 	// mode & 1: value is a module id, require it
       
    54 /******/ 	// mode & 2: merge all properties of value into the ns
       
    55 /******/ 	// mode & 4: return value when already ns object
       
    56 /******/ 	// mode & 8|1: behave like require
       
    57 /******/ 	__webpack_require__.t = function(value, mode) {
       
    58 /******/ 		if(mode & 1) value = __webpack_require__(value);
       
    59 /******/ 		if(mode & 8) return value;
       
    60 /******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
       
    61 /******/ 		var ns = Object.create(null);
       
    62 /******/ 		__webpack_require__.r(ns);
       
    63 /******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
       
    64 /******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
       
    65 /******/ 		return ns;
       
    66 /******/ 	};
       
    67 /******/
       
    68 /******/ 	// getDefaultExport function for compatibility with non-harmony modules
       
    69 /******/ 	__webpack_require__.n = function(module) {
       
    70 /******/ 		var getter = module && module.__esModule ?
       
    71 /******/ 			function getDefault() { return module['default']; } :
       
    72 /******/ 			function getModuleExports() { return module; };
       
    73 /******/ 		__webpack_require__.d(getter, 'a', getter);
       
    74 /******/ 		return getter;
       
    75 /******/ 	};
       
    76 /******/
       
    77 /******/ 	// Object.prototype.hasOwnProperty.call
       
    78 /******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
       
    79 /******/
       
    80 /******/ 	// __webpack_public_path__
       
    81 /******/ 	__webpack_require__.p = "";
       
    82 /******/
       
    83 /******/
       
    84 /******/ 	// Load entry module and return exports
       
    85 /******/ 	return __webpack_require__(__webpack_require__.s = "zbAn");
       
    86 /******/ })
       
    87 /************************************************************************/
    35 /************************************************************************/
    88 /******/ ({
    36 var __webpack_exports__ = {};
    89 
       
    90 /***/ "zbAn":
       
    91 /***/ (function(module, __webpack_exports__, __webpack_require__) {
       
    92 
       
    93 "use strict";
       
    94 __webpack_require__.r(__webpack_exports__);
    37 __webpack_require__.r(__webpack_exports__);
    95 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "autop", function() { return autop; });
    38 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
    96 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removep", function() { return removep; });
    39 /* harmony export */   "autop": function() { return /* binding */ autop; },
       
    40 /* harmony export */   "removep": function() { return /* binding */ removep; }
       
    41 /* harmony export */ });
    97 /**
    42 /**
    98  * The regular expression for an HTML element.
    43  * The regular expression for an HTML element.
    99  *
    44  *
   100  * @type {RegExp}
    45  * @type {RegExp}
   101  */
    46  */
   130   /* eslint-enable no-multi-spaces */
    75   /* eslint-enable no-multi-spaces */
   131 })();
    76 })();
   132 /**
    77 /**
   133  * Separate HTML elements and comments from the text.
    78  * Separate HTML elements and comments from the text.
   134  *
    79  *
   135  * @param  {string} input The text which has to be formatted.
    80  * @param {string} input The text which has to be formatted.
   136  * @return {string[]}        The formatted text.
    81  *
       
    82  * @return {string[]} The formatted text.
   137  */
    83  */
   138 
    84 
   139 
    85 
   140 function htmlSplit(input) {
    86 function htmlSplit(input) {
   141   const parts = [];
    87   const parts = [];
   162   return parts;
   108   return parts;
   163 }
   109 }
   164 /**
   110 /**
   165  * Replace characters or phrases within HTML elements only.
   111  * Replace characters or phrases within HTML elements only.
   166  *
   112  *
   167  * @param  {string}                haystack     The text which has to be formatted.
   113  * @param {string}                haystack     The text which has to be formatted.
   168  * @param  {Record<string,string>} replacePairs In the form {from: 'to', …}.
   114  * @param {Record<string,string>} replacePairs In the form {from: 'to', …}.
   169  * @return {string}                             The formatted text.
   115  *
       
   116  * @return {string} The formatted text.
   170  */
   117  */
   171 
   118 
   172 
   119 
   173 function replaceInHtmlTags(haystack, replacePairs) {
   120 function replaceInHtmlTags(haystack, replacePairs) {
   174   // Find all elements.
   121   // Find all elements.
   201  *
   148  *
   202  * A group of regex replaces used to identify text formatted with newlines and
   149  * A group of regex replaces used to identify text formatted with newlines and
   203  * replace double line-breaks with HTML paragraph tags. The remaining line-
   150  * replace double line-breaks with HTML paragraph tags. The remaining line-
   204  * breaks after conversion become `<br />` tags, unless br is set to 'false'.
   151  * breaks after conversion become `<br />` tags, unless br is set to 'false'.
   205  *
   152  *
   206  * @param  {string}    text The text which has to be formatted.
   153  * @param {string}  text The text which has to be formatted.
   207  * @param  {boolean}   br   Optional. If set, will convert all remaining line-
   154  * @param {boolean} br   Optional. If set, will convert all remaining line-
   208  *                          breaks after paragraphing. Default true.
   155  *                       breaks after paragraphing. Default true.
   209  *
   156  *
   210  * @example
   157  * @example
   211  *```js
   158  *```js
   212  * import { autop } from '@wordpress/autop';
   159  * import { autop } from '@wordpress/autop';
   213  * autop( 'my text' ); // "<p>my text</p>"
   160  * autop( 'my text' ); // "<p>my text</p>"
   214  * ```
   161  * ```
   215  *
   162  *
   216  * @return {string}         Text which has been converted into paragraph tags.
   163  * @return {string} Text which has been converted into paragraph tags.
   217  */
   164  */
   218 
   165 
   219 
   166 
   220 function autop(text, br = true) {
   167 function autop(text) {
       
   168   let br = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
   221   const preTags = [];
   169   const preTags = [];
   222 
   170 
   223   if (text.trim() === '') {
   171   if (text.trim() === '') {
   224     return '';
   172     return '';
   225   } // Just to make things a little easier, pad the end.
   173   } // Just to make things a little easier, pad the end.
   358  * Replaces `<p>` tags with two line breaks. "Opposite" of autop().
   306  * Replaces `<p>` tags with two line breaks. "Opposite" of autop().
   359  *
   307  *
   360  * Replaces `<p>` tags with two line breaks except where the `<p>` has attributes.
   308  * Replaces `<p>` tags with two line breaks except where the `<p>` has attributes.
   361  * Unifies whitespace. Indents `<li>`, `<dt>` and `<dd>` for better readability.
   309  * Unifies whitespace. Indents `<li>`, `<dt>` and `<dd>` for better readability.
   362  *
   310  *
   363  * @param  {string} html The content from the editor.
   311  * @param {string} html The content from the editor.
   364  *
   312  *
   365  * @example
   313  * @example
   366  * ```js
   314  * ```js
   367  * import { removep } from '@wordpress/autop';
   315  * import { removep } from '@wordpress/autop';
   368  * removep( '<p>my text</p>' ); // "my text"
   316  * removep( '<p>my text</p>' ); // "my text"
   369  * ```
   317  * ```
   370  *
   318  *
   371  * @return {string}      The content with stripped paragraph tags.
   319  * @return {string} The content with stripped paragraph tags.
   372  */
   320  */
   373 
   321 
   374 function removep(html) {
   322 function removep(html) {
   375   const blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset|figure';
   323   const blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset|figure';
   376   const blocklist1 = blocklist + '|div|p';
   324   const blocklist1 = blocklist + '|div|p';
   487   }
   435   }
   488 
   436 
   489   return html;
   437   return html;
   490 }
   438 }
   491 
   439 
   492 
   440 (window.wp = window.wp || {}).autop = __webpack_exports__;
   493 /***/ })
   441 /******/ })()
   494 
   442 ;
   495 /******/ });