"use strict"; var wp; (wp ||= {}).autop = (() => { var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/autop/build-module/index.js var index_exports = {}; __export(index_exports, { autop: () => autop, removep: () => removep }); var htmlSplitRegex = (() => { const comments = "!(?:-(?!->)[^\\-]*)*(?:-->)?"; const cdata = "!\\[CDATA\\[[^\\]]*(?:](?!]>)[^\\]]*)*?(?:]]>)?"; const escaped = "(?=!--|!\\[CDATA\\[)((?=!-)" + // If yes, which type? comments + "|" + cdata + ")"; const regex = "(<(" + // Conditional expression follows. escaped + // Find end of escaped element. "|[^>]*>?))"; return new RegExp(regex); })(); function htmlSplit(input) { const parts = []; let workingInput = input; let match; while (match = workingInput.match(htmlSplitRegex)) { const index = 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; } function replaceInHtmlTags(haystack, replacePairs) { const textArr = htmlSplit(haystack); let changed = false; const needles = Object.keys(replacePairs); 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; break; } } } if (changed) { haystack = textArr.join(""); } return haystack; } function autop(text, br = true) { const preTags = []; if (text.trim() === "") { return ""; } text = text + "\n"; 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; } 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)"; text = text.replace( new RegExp("(<" + allBlocks + "[\\s/>])", "g"), "\n\n$1" ); text = text.replace( new RegExp("()", "g"), "$1\n\n" ); text = text.replace(/\r\n|\r/g, "\n"); text = replaceInHtmlTags(text, { "\n": " " }); if (text.indexOf("\s*/g, ""); } 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"); } if (text.indexOf("\]]*[>\]])\s*/g, "$1"); text = text.replace(/\s*([<\[]\/(?:audio|video)[>\]])/g, "$1"); text = text.replace(/\s*(<(?:source|track)[^>]*>)\s*/g, "$1"); } if (text.indexOf("]*>)/, "$1"); text = text.replace(/<\/figcaption>\s*/, ""); } text = text.replace(/\n\n+/g, "\n\n"); const texts = text.split(/\n\s*\n/).filter(Boolean); text = ""; texts.forEach((textPiece) => { text += "

" + textPiece.replace(/^\n*|\n*$/g, "") + "

\n"; }); text = text.replace(/

\s*<\/p>/g, ""); text = text.replace( /

([^<]+)<\/(div|address|form)>/g, "

$1

" ); text = text.replace( new RegExp("

\\s*(]*>)\\s*

", "g"), "$1" ); text = text.replace(/

(/g, "$1"); text = text.replace(/

]*)>/gi, "

"); text = text.replace(/<\/blockquote><\/p>/g, "

"); text = text.replace( new RegExp("

\\s*(]*>)", "g"), "$1" ); text = text.replace( new RegExp("(]*>)\\s*

", "g"), "$1" ); if (br) { text = text.replace( /<(script|style).*?<\/\\1>/g, (match) => match[0].replace(/\n/g, "") ); text = text.replace(/
|/g, "
"); text = text.replace( /(
)?\s*\n/g, (a, b) => b ? a : "
\n" ); text = text.replace(//g, "\n"); } text = text.replace( new RegExp("(]*>)\\s*
", "g"), "$1" ); text = text.replace( /
(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)/g, "$1" ); text = text.replace(/\n<\/p>$/g, "

"); preTags.forEach((preTag) => { const [name, original] = preTag; text = text.replace(name, () => original); }); if (-1 !== text.indexOf("")) { text = text.replace(/\s?\s?/g, "\n"); } return text; } function removep(html) { const blocklist = "blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset|figure"; const blocklist1 = blocklist + "|div|p"; const blocklist2 = blocklist + "|pre"; const preserve = []; let preserveLinebreaks = false; let preserveBr = false; if (!html) { return ""; } if (html.indexOf("]*>[\s\S]*?<\/\1>/g, (match) => { preserve.push(match); return ""; } ); } if (html.indexOf("]*>[\s\S]+?<\/pre>/g, (a) => { a = a.replace(/
(\r\n|\n)?/g, ""); a = a.replace(/<\/?p( [^>]*)?>(\r\n|\n)?/g, ""); return a.replace(/\r?\n/g, ""); }); } if (html.indexOf("[caption") !== -1) { preserveBr = true; html = html.replace(/\[caption[\s\S]+?\[\/caption\]/g, (a) => { return a.replace(/]*)>/g, "").replace(/[\r\n\t]+/, ""); }); } html = html.replace( new RegExp("\\s*\\s*", "g"), "\n" ); html = html.replace( new RegExp("\\s*<((?:" + blocklist1 + ")(?: [^>]*)?)>", "g"), "\n<$1>" ); html = html.replace(/(

]+>[\s\S]*?)<\/p>/g, "$1"); html = html.replace(/]*)?>\s*

/gi, "\n\n"); html = html.replace(/\s*

/gi, ""); html = html.replace(/\s*<\/p>\s*/gi, "\n\n"); html = html.replace(/\n[\s\u00a0]+\n/g, "\n\n"); html = html.replace(/(\s*)
\s*/gi, (_, space) => { if (space && space.indexOf("\n") !== -1) { return "\n\n"; } return "\n"; }); html = html.replace(/\s*

\s*/g, "
\n"); html = html.replace( /\s*\[caption([^\[]+)\[\/caption\]\s*/gi, "\n\n[caption$1[/caption]\n\n" ); html = html.replace(/caption\]\n\n+\[caption/g, "caption]\n\n[caption"); html = html.replace( new RegExp("\\s*<((?:" + blocklist2 + ")(?: [^>]*)?)\\s*>", "g"), "\n<$1>" ); html = html.replace( new RegExp("\\s*\\s*", "g"), "\n" ); html = html.replace(/<((li|dt|dd)[^>]*)>/g, " <$1>"); if (html.indexOf("/g, "\n"); } if (html.indexOf("]*)?>\s*/g, "\n\n\n\n"); } if (html.indexOf("/g, (a) => { return a.replace(/[\r\n]+/g, ""); }); } html = html.replace(/<\/p#>/g, "

\n"); html = html.replace(/\s*(

]+>[\s\S]*?<\/p>)/g, "\n$1"); html = html.replace(/^\s+/, ""); html = html.replace(/[\s\u00a0]+$/, ""); if (preserveLinebreaks) { html = html.replace(//g, "\n"); } if (preserveBr) { html = html.replace(/]*)>/g, ""); } if (preserve.length) { html = html.replace(//g, () => { return preserve.shift(); }); } return html; } return __toCommonJS(index_exports); })();