/******/ (function() { // webpackBootstrap /******/ "use strict"; /******/ // The require scope /******/ var __webpack_require__ = {}; /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ !function() { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = function(exports, definition) { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ !function() { /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } /******/ }(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ !function() { /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ }(); /******/ /************************************************************************/ var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "autop": function() { return /* binding */ autop; }, /* harmony export */ "removep": function() { return /* binding */ removep; } /* harmony export */ }); /** * The regular expression for an HTML element. * * @type {RegExp} */ const htmlSplitRegex = (() => { /* eslint-disable no-multi-spaces */ const comments = '!' + // Start of comment, after the <. '(?:' + // Unroll the loop: Consume everything until --> is found. '-(?!->)' + // Dash not followed by end of comment. '[^\\-]*' + // Consume non-dashes. ')*' + // Loop possessively. '(?:-->)?'; // End of comment. If not found, match all input. const cdata = '!\\[CDATA\\[' + // Start of comment, after the <. '[^\\]]*' + // Consume non-]. '(?:' + // Unroll the loop: Consume everything until ]]> is found. '](?!]>)' + // One ] not followed by end of comment. '[^\\]]*' + // Consume non-]. ')*?' + // Loop possessively. '(?:]]>)?'; // End of comment. If not found, match all input. const escaped = '(?=' + // Is the element escaped? '!--' + '|' + '!\\[CDATA\\[' + ')' + '((?=!-)' + // If yes, which type? comments + '|' + cdata + ')'; const regex = '(' + // Capture the entire match. '<' + // Find start of element. '(' + // Conditional expression follows. escaped + // Find end of escaped element. '|' + // ... else ... '[^>]*>?' + // Find end of normal element. ')' + ')'; return new RegExp(regex); /* eslint-enable no-multi-spaces */ })(); /** * Separate HTML elements and comments from the text. * * @param {string} input The text which has to be formatted. * * @return {string[]} The formatted text. */ function htmlSplit(input) { const parts = []; let workingInput = input; let match; while (match = workingInput.match(htmlSplitRegex)) { // The `match` result, when invoked on a RegExp with the `g` flag (`/foo/g`) will not include `index`. // If the `g` flag is omitted, `index` is included. // `htmlSplitRegex` does not have the `g` flag so we can assert it will have an index number. // Assert `match.index` is a number. const index = /** @type {number} */ match.index; parts.push(workingInput.slice(0, index)); parts.push(match[0]); workingInput = workingInput.slice(index + match[0].length); } if (workingInput.length) { parts.push(workingInput); } return parts; } /** * Replace characters or phrases within HTML elements only. * * @param {string} haystack The text which has to be formatted. * @param {Record} replacePairs In the form {from: 'to', …}. * * @return {string} The formatted text. */ function replaceInHtmlTags(haystack, replacePairs) { // Find all elements. const textArr = htmlSplit(haystack); let changed = false; // Extract all needles. const needles = Object.keys(replacePairs); // Loop through delimiters (elements) only. for (let i = 1; i < textArr.length; i += 2) { for (let j = 0; j < needles.length; j++) { const needle = needles[j]; if (-1 !== textArr[i].indexOf(needle)) { textArr[i] = textArr[i].replace(new RegExp(needle, 'g'), replacePairs[needle]); changed = true; // After one strtr() break out of the foreach loop and look at next element. break; } } } if (changed) { haystack = textArr.join(''); } return haystack; } /** * Replaces double line-breaks with paragraph elements. * * A group of regex replaces used to identify text formatted with newlines and * replace double line-breaks with HTML paragraph tags. The remaining line- * breaks after conversion become `
` tags, unless br is set to 'false'. * * @param {string} text The text which has to be formatted. * @param {boolean} br Optional. If set, will convert all remaining line- * breaks after paragraphing. Default true. * * @example *```js * import { autop } from '@wordpress/autop'; * autop( 'my text' ); // "

my text

" * ``` * * @return {string} Text which has been converted into paragraph tags. */ function autop(text) { let br = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; const preTags = []; if (text.trim() === '') { return ''; } // Just to make things a little easier, pad the end. text = text + '\n'; /* * Pre tags shouldn't be touched by autop. * Replace pre tags with placeholders and bring them back after autop. */ if (text.indexOf(''); const lastText = textParts.pop(); text = ''; for (let i = 0; i < textParts.length; i++) { const textPart = textParts[i]; const start = textPart.indexOf(''; preTags.push([name, textPart.substr(start) + '']); text += textPart.substr(0, start) + name; } text += lastText; } // Change multiple
s into two line breaks, which will turn into paragraphs. text = text.replace(/\s*/g, '\n\n'); const allBlocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; // Add a double line break above block-level opening tags. text = text.replace(new RegExp('(<' + allBlocks + '[\\s/>])', 'g'), '\n\n$1'); // Add a double line break below block-level closing tags. text = text.replace(new RegExp('()', 'g'), '$1\n\n'); // Standardize newline characters to "\n". text = text.replace(/\r\n|\r/g, '\n'); // Find newlines in all elements and add placeholders. text = replaceInHtmlTags(text, { '\n': ' ' }); // Collapse line breaks before and after '); } /* * Collapse line breaks inside elements, before and elements * so they don't get autop'd. */ if (text.indexOf('') !== -1) { text = text.replace(/(]*>)\s*/g, '$1'); text = text.replace(/\s*<\/object>/g, ''); text = text.replace(/\s*(<\/?(?:param|embed)[^>]*>)\s*/g, '$1'); } /* * Collapse line breaks inside