author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1 |
/******/ (() => { // webpackBootstrap |
19 | 2 |
/******/ "use strict"; |
3 |
/******/ // The require scope |
|
4 |
/******/ var __webpack_require__ = {}; |
|
5 |
/******/ |
|
6 |
/************************************************************************/ |
|
7 |
/******/ /* webpack/runtime/define property getters */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8 |
/******/ (() => { |
19 | 9 |
/******/ // define getter functions for harmony exports |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
10 |
/******/ __webpack_require__.d = (exports, definition) => { |
19 | 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 |
/******/ } |
|
9 | 16 |
/******/ }; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
17 |
/******/ })(); |
19 | 18 |
/******/ |
19 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
20 |
/******/ (() => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
21 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
22 |
/******/ })(); |
19 | 23 |
/******/ |
24 |
/******/ /* webpack/runtime/make namespace object */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
25 |
/******/ (() => { |
19 | 26 |
/******/ // define __esModule on exports |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
/******/ __webpack_require__.r = (exports) => { |
19 | 28 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
29 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
30 |
/******/ } |
|
31 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
32 |
/******/ }; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
/******/ })(); |
19 | 34 |
/******/ |
9 | 35 |
/************************************************************************/ |
19 | 36 |
var __webpack_exports__ = {}; |
9 | 37 |
__webpack_require__.r(__webpack_exports__); |
19 | 38 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
39 |
/* harmony export */ autop: () => (/* binding */ autop), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
40 |
/* harmony export */ removep: () => (/* binding */ removep) |
19 | 41 |
/* harmony export */ }); |
9 | 42 |
/** |
43 |
* The regular expression for an HTML element. |
|
44 |
* |
|
16 | 45 |
* @type {RegExp} |
9 | 46 |
*/ |
18 | 47 |
const htmlSplitRegex = (() => { |
9 | 48 |
/* eslint-disable no-multi-spaces */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
49 |
const comments = '!' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
50 |
// Start of comment, after the <. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
51 |
'(?:' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
52 |
// Unroll the loop: Consume everything until --> is found. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
53 |
'-(?!->)' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
54 |
// Dash not followed by end of comment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
55 |
'[^\\-]*' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
56 |
// Consume non-dashes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
57 |
')*' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
58 |
// Loop possessively. |
9 | 59 |
'(?:-->)?'; // End of comment. If not found, match all input. |
60 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
const cdata = '!\\[CDATA\\[' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
62 |
// Start of comment, after the <. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
'[^\\]]*' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
// Consume non-]. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
'(?:' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
// Unroll the loop: Consume everything until ]]> is found. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
'](?!]>)' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
68 |
// One ] not followed by end of comment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
69 |
'[^\\]]*' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
70 |
// Consume non-]. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
71 |
')*?' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
72 |
// Loop possessively. |
9 | 73 |
'(?:]]>)?'; // End of comment. If not found, match all input. |
74 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
75 |
const escaped = '(?=' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
76 |
// Is the element escaped? |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
77 |
'!--' + '|' + '!\\[CDATA\\[' + ')' + '((?=!-)' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
78 |
// If yes, which type? |
9 | 79 |
comments + '|' + cdata + ')'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
80 |
const regex = '(' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
81 |
// Capture the entire match. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
82 |
'<' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
83 |
// Find start of element. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
84 |
'(' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
85 |
// Conditional expression follows. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
86 |
escaped + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
87 |
// Find end of escaped element. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
88 |
'|' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
89 |
// ... else ... |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
90 |
'[^>]*>?' + |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
91 |
// Find end of normal element. |
9 | 92 |
')' + ')'; |
93 |
return new RegExp(regex); |
|
94 |
/* eslint-enable no-multi-spaces */ |
|
18 | 95 |
})(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
96 |
|
9 | 97 |
/** |
98 |
* Separate HTML elements and comments from the text. |
|
99 |
* |
|
19 | 100 |
* @param {string} input The text which has to be formatted. |
101 |
* |
|
102 |
* @return {string[]} The formatted text. |
|
9 | 103 |
*/ |
104 |
function htmlSplit(input) { |
|
18 | 105 |
const parts = []; |
106 |
let workingInput = input; |
|
107 |
let match; |
|
9 | 108 |
while (match = workingInput.match(htmlSplitRegex)) { |
16 | 109 |
// The `match` result, when invoked on a RegExp with the `g` flag (`/foo/g`) will not include `index`. |
110 |
// If the `g` flag is omitted, `index` is included. |
|
111 |
// `htmlSplitRegex` does not have the `g` flag so we can assert it will have an index number. |
|
112 |
// Assert `match.index` is a number. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
113 |
const index = /** @type {number} */match.index; |
16 | 114 |
parts.push(workingInput.slice(0, index)); |
9 | 115 |
parts.push(match[0]); |
16 | 116 |
workingInput = workingInput.slice(index + match[0].length); |
9 | 117 |
} |
118 |
if (workingInput.length) { |
|
119 |
parts.push(workingInput); |
|
120 |
} |
|
121 |
return parts; |
|
122 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
|
9 | 124 |
/** |
125 |
* Replace characters or phrases within HTML elements only. |
|
126 |
* |
|
19 | 127 |
* @param {string} haystack The text which has to be formatted. |
128 |
* @param {Record<string,string>} replacePairs In the form {from: 'to', …}. |
|
129 |
* |
|
130 |
* @return {string} The formatted text. |
|
9 | 131 |
*/ |
132 |
function replaceInHtmlTags(haystack, replacePairs) { |
|
133 |
// Find all elements. |
|
18 | 134 |
const textArr = htmlSplit(haystack); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
135 |
let changed = false; |
9 | 136 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
137 |
// Extract all needles. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
138 |
const needles = Object.keys(replacePairs); |
9 | 139 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
// Loop through delimiters (elements) only. |
18 | 141 |
for (let i = 1; i < textArr.length; i += 2) { |
142 |
for (let j = 0; j < needles.length; j++) { |
|
143 |
const needle = needles[j]; |
|
9 | 144 |
if (-1 !== textArr[i].indexOf(needle)) { |
145 |
textArr[i] = textArr[i].replace(new RegExp(needle, 'g'), replacePairs[needle]); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
146 |
changed = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
147 |
// After one strtr() break out of the foreach loop and look at next element. |
9 | 148 |
break; |
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
if (changed) { |
|
153 |
haystack = textArr.join(''); |
|
154 |
} |
|
155 |
return haystack; |
|
156 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
157 |
|
9 | 158 |
/** |
159 |
* Replaces double line-breaks with paragraph elements. |
|
160 |
* |
|
161 |
* A group of regex replaces used to identify text formatted with newlines and |
|
162 |
* replace double line-breaks with HTML paragraph tags. The remaining line- |
|
163 |
* breaks after conversion become `<br />` tags, unless br is set to 'false'. |
|
164 |
* |
|
19 | 165 |
* @param {string} text The text which has to be formatted. |
166 |
* @param {boolean} br Optional. If set, will convert all remaining line- |
|
167 |
* breaks after paragraphing. Default true. |
|
9 | 168 |
* |
169 |
* @example |
|
170 |
*```js |
|
171 |
* import { autop } from '@wordpress/autop'; |
|
172 |
* autop( 'my text' ); // "<p>my text</p>" |
|
173 |
* ``` |
|
174 |
* |
|
19 | 175 |
* @return {string} Text which has been converted into paragraph tags. |
9 | 176 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
function autop(text, br = true) { |
18 | 178 |
const preTags = []; |
9 | 179 |
if (text.trim() === '') { |
180 |
return ''; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
181 |
} |
9 | 182 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
183 |
// Just to make things a little easier, pad the end. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
184 |
text = text + '\n'; |
9 | 185 |
|
186 |
/* |
|
187 |
* Pre tags shouldn't be touched by autop. |
|
188 |
* Replace pre tags with placeholders and bring them back after autop. |
|
189 |
*/ |
|
190 |
if (text.indexOf('<pre') !== -1) { |
|
18 | 191 |
const textParts = text.split('</pre>'); |
192 |
const lastText = textParts.pop(); |
|
9 | 193 |
text = ''; |
18 | 194 |
for (let i = 0; i < textParts.length; i++) { |
195 |
const textPart = textParts[i]; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
196 |
const start = textPart.indexOf('<pre'); |
9 | 197 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
198 |
// Malformed html? |
9 | 199 |
if (start === -1) { |
200 |
text += textPart; |
|
201 |
continue; |
|
202 |
} |
|
18 | 203 |
const name = '<pre wp-pre-tag-' + i + '></pre>'; |
9 | 204 |
preTags.push([name, textPart.substr(start) + '</pre>']); |
205 |
text += textPart.substr(0, start) + name; |
|
206 |
} |
|
207 |
text += lastText; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
208 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
209 |
// Change multiple <br>s into two line breaks, which will turn into paragraphs. |
9 | 210 |
text = text.replace(/<br\s*\/?>\s*<br\s*\/?>/g, '\n\n'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
211 |
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)'; |
9 | 212 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
213 |
// Add a double line break above block-level opening tags. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
214 |
text = text.replace(new RegExp('(<' + allBlocks + '[\\s/>])', 'g'), '\n\n$1'); |
9 | 215 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
216 |
// Add a double line break below block-level closing tags. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
217 |
text = text.replace(new RegExp('(</' + allBlocks + '>)', 'g'), '$1\n\n'); |
9 | 218 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
219 |
// Standardize newline characters to "\n". |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
220 |
text = text.replace(/\r\n|\r/g, '\n'); |
9 | 221 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
222 |
// Find newlines in all elements and add placeholders. |
9 | 223 |
text = replaceInHtmlTags(text, { |
224 |
'\n': ' <!-- wpnl --> ' |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
225 |
}); |
9 | 226 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
227 |
// Collapse line breaks before and after <option> elements so they don't get autop'd. |
9 | 228 |
if (text.indexOf('<option') !== -1) { |
229 |
text = text.replace(/\s*<option/g, '<option'); |
|
230 |
text = text.replace(/<\/option>\s*/g, '</option>'); |
|
231 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
|
9 | 233 |
/* |
234 |
* Collapse line breaks inside <object> elements, before <param> and <embed> elements |
|
235 |
* so they don't get autop'd. |
|
236 |
*/ |
|
237 |
if (text.indexOf('</object>') !== -1) { |
|
238 |
text = text.replace(/(<object[^>]*>)\s*/g, '$1'); |
|
239 |
text = text.replace(/\s*<\/object>/g, '</object>'); |
|
240 |
text = text.replace(/\s*(<\/?(?:param|embed)[^>]*>)\s*/g, '$1'); |
|
241 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
242 |
|
9 | 243 |
/* |
244 |
* Collapse line breaks inside <audio> and <video> elements, |
|
245 |
* before and after <source> and <track> elements. |
|
246 |
*/ |
|
247 |
if (text.indexOf('<source') !== -1 || text.indexOf('<track') !== -1) { |
|
248 |
text = text.replace(/([<\[](?:audio|video)[^>\]]*[>\]])\s*/g, '$1'); |
|
249 |
text = text.replace(/\s*([<\[]\/(?:audio|video)[>\]])/g, '$1'); |
|
250 |
text = text.replace(/\s*(<(?:source|track)[^>]*>)\s*/g, '$1'); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
251 |
} |
9 | 252 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
253 |
// Collapse line breaks before and after <figcaption> elements. |
9 | 254 |
if (text.indexOf('<figcaption') !== -1) { |
255 |
text = text.replace(/\s*(<figcaption[^>]*>)/, '$1'); |
|
256 |
text = text.replace(/<\/figcaption>\s*/, '</figcaption>'); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
257 |
} |
9 | 258 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
259 |
// Remove more than two contiguous line breaks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
260 |
text = text.replace(/\n\n+/g, '\n\n'); |
9 | 261 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
262 |
// Split up the contents into an array of strings, separated by double line breaks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
263 |
const texts = text.split(/\n\s*\n/).filter(Boolean); |
9 | 264 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
// Reset text prior to rebuilding. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
text = ''; |
9 | 267 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
268 |
// Rebuild the content as a string, wrapping every bit with a <p>. |
18 | 269 |
texts.forEach(textPiece => { |
9 | 270 |
text += '<p>' + textPiece.replace(/^\n*|\n*$/g, '') + '</p>\n'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
271 |
}); |
9 | 272 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
// Under certain strange conditions it could create a P of entirely whitespace. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
274 |
text = text.replace(/<p>\s*<\/p>/g, ''); |
9 | 275 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
276 |
// Add a closing <p> inside <div>, <address>, or <form> tag if missing. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
277 |
text = text.replace(/<p>([^<]+)<\/(div|address|form)>/g, '<p>$1</p></$2>'); |
9 | 278 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
279 |
// If an opening or closing block element tag is wrapped in a <p>, unwrap it. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
280 |
text = text.replace(new RegExp('<p>\\s*(</?' + allBlocks + '[^>]*>)\\s*</p>', 'g'), '$1'); |
9 | 281 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
282 |
// In some cases <li> may get wrapped in <p>, fix them. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
283 |
text = text.replace(/<p>(<li.+?)<\/p>/g, '$1'); |
9 | 284 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
285 |
// If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>. |
9 | 286 |
text = text.replace(/<p><blockquote([^>]*)>/gi, '<blockquote$1><p>'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
287 |
text = text.replace(/<\/blockquote><\/p>/g, '</p></blockquote>'); |
9 | 288 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
289 |
// If an opening or closing block element tag is preceded by an opening <p> tag, remove it. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
290 |
text = text.replace(new RegExp('<p>\\s*(</?' + allBlocks + '[^>]*>)', 'g'), '$1'); |
9 | 291 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
292 |
// If an opening or closing block element tag is followed by a closing <p> tag, remove it. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
293 |
text = text.replace(new RegExp('(</?' + allBlocks + '[^>]*>)\\s*</p>', 'g'), '$1'); |
9 | 294 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
295 |
// Optionally insert line breaks. |
9 | 296 |
if (br) { |
297 |
// Replace newlines that shouldn't be touched with a placeholder. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
298 |
text = text.replace(/<(script|style).*?<\/\\1>/g, match => match[0].replace(/\n/g, '<WPPreserveNewline />')); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
299 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
300 |
// Normalize <br> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
301 |
text = text.replace(/<br>|<br\/>/g, '<br />'); |
9 | 302 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
303 |
// Replace any new line characters that aren't preceded by a <br /> with a <br />. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
text = text.replace(/(<br \/>)?\s*\n/g, (a, b) => b ? a : '<br />\n'); |
9 | 305 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
306 |
// Replace newline placeholders with newlines. |
9 | 307 |
text = text.replace(/<WPPreserveNewline \/>/g, '\n'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
308 |
} |
9 | 309 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
310 |
// If a <br /> tag is after an opening or closing block tag, remove it. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
311 |
text = text.replace(new RegExp('(</?' + allBlocks + '[^>]*>)\\s*<br />', 'g'), '$1'); |
9 | 312 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
313 |
// If a <br /> tag is before a subset of opening or closing block tags, remove it. |
9 | 314 |
text = text.replace(/<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)/g, '$1'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
315 |
text = text.replace(/\n<\/p>$/g, '</p>'); |
9 | 316 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
317 |
// Replace placeholder <pre> tags with their original content. |
18 | 318 |
preTags.forEach(preTag => { |
319 |
const [name, original] = preTag; |
|
9 | 320 |
text = text.replace(name, original); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
}); |
9 | 322 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
323 |
// Restore newlines in all elements. |
9 | 324 |
if (-1 !== text.indexOf('<!-- wpnl -->')) { |
325 |
text = text.replace(/\s?<!-- wpnl -->\s?/g, '\n'); |
|
326 |
} |
|
327 |
return text; |
|
328 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
329 |
|
9 | 330 |
/** |
331 |
* Replaces `<p>` tags with two line breaks. "Opposite" of autop(). |
|
332 |
* |
|
333 |
* Replaces `<p>` tags with two line breaks except where the `<p>` has attributes. |
|
334 |
* Unifies whitespace. Indents `<li>`, `<dt>` and `<dd>` for better readability. |
|
335 |
* |
|
19 | 336 |
* @param {string} html The content from the editor. |
9 | 337 |
* |
338 |
* @example |
|
339 |
* ```js |
|
340 |
* import { removep } from '@wordpress/autop'; |
|
341 |
* removep( '<p>my text</p>' ); // "my text" |
|
342 |
* ``` |
|
343 |
* |
|
19 | 344 |
* @return {string} The content with stripped paragraph tags. |
9 | 345 |
*/ |
346 |
function removep(html) { |
|
18 | 347 |
const blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset|figure'; |
348 |
const blocklist1 = blocklist + '|div|p'; |
|
349 |
const blocklist2 = blocklist + '|pre'; |
|
16 | 350 |
/** @type {string[]} */ |
18 | 351 |
const preserve = []; |
352 |
let preserveLinebreaks = false; |
|
353 |
let preserveBr = false; |
|
9 | 354 |
if (!html) { |
355 |
return ''; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
356 |
} |
9 | 357 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
358 |
// Protect script and style tags. |
9 | 359 |
if (html.indexOf('<script') !== -1 || html.indexOf('<style') !== -1) { |
18 | 360 |
html = html.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/g, match => { |
9 | 361 |
preserve.push(match); |
362 |
return '<wp-preserve>'; |
|
363 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
364 |
} |
9 | 365 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
366 |
// Protect pre tags. |
9 | 367 |
if (html.indexOf('<pre') !== -1) { |
368 |
preserveLinebreaks = true; |
|
18 | 369 |
html = html.replace(/<pre[^>]*>[\s\S]+?<\/pre>/g, a => { |
9 | 370 |
a = a.replace(/<br ?\/?>(\r\n|\n)?/g, '<wp-line-break>'); |
371 |
a = a.replace(/<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-line-break>'); |
|
372 |
return a.replace(/\r?\n/g, '<wp-line-break>'); |
|
373 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
} |
9 | 375 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
376 |
// Remove line breaks but keep <br> tags inside image captions. |
9 | 377 |
if (html.indexOf('[caption') !== -1) { |
378 |
preserveBr = true; |
|
18 | 379 |
html = html.replace(/\[caption[\s\S]+?\[\/caption\]/g, a => { |
9 | 380 |
return a.replace(/<br([^>]*)>/g, '<wp-temp-br$1>').replace(/[\r\n\t]+/, ''); |
381 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
382 |
} |
9 | 383 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
384 |
// Normalize white space characters before and after block tags. |
9 | 385 |
html = html.replace(new RegExp('\\s*</(' + blocklist1 + ')>\\s*', 'g'), '</$1>\n'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
386 |
html = html.replace(new RegExp('\\s*<((?:' + blocklist1 + ')(?: [^>]*)?)>', 'g'), '\n<$1>'); |
9 | 387 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
388 |
// Mark </p> if it has any attributes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
389 |
html = html.replace(/(<p [^>]+>[\s\S]*?)<\/p>/g, '$1</p#>'); |
9 | 390 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
391 |
// Preserve the first <p> inside a <div>. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
392 |
html = html.replace(/<div( [^>]*)?>\s*<p>/gi, '<div$1>\n\n'); |
9 | 393 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
394 |
// Remove paragraph tags. |
9 | 395 |
html = html.replace(/\s*<p>/gi, ''); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
396 |
html = html.replace(/\s*<\/p>\s*/gi, '\n\n'); |
9 | 397 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
398 |
// Normalize white space chars and remove multiple line breaks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
399 |
html = html.replace(/\n[\s\u00a0]+\n/g, '\n\n'); |
9 | 400 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
401 |
// Replace <br> tags with line breaks. |
18 | 402 |
html = html.replace(/(\s*)<br ?\/?>\s*/gi, (_, space) => { |
9 | 403 |
if (space && space.indexOf('\n') !== -1) { |
404 |
return '\n\n'; |
|
405 |
} |
|
406 |
return '\n'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
407 |
}); |
9 | 408 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
409 |
// Fix line breaks around <div>. |
9 | 410 |
html = html.replace(/\s*<div/g, '\n<div'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
411 |
html = html.replace(/<\/div>\s*/g, '</div>\n'); |
9 | 412 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
// Fix line breaks around caption shortcodes. |
9 | 414 |
html = html.replace(/\s*\[caption([^\[]+)\[\/caption\]\s*/gi, '\n\n[caption$1[/caption]\n\n'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
html = html.replace(/caption\]\n\n+\[caption/g, 'caption]\n\n[caption'); |
9 | 416 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
// Pad block elements tags with a line break. |
9 | 418 |
html = html.replace(new RegExp('\\s*<((?:' + blocklist2 + ')(?: [^>]*)?)\\s*>', 'g'), '\n<$1>'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
html = html.replace(new RegExp('\\s*</(' + blocklist2 + ')>\\s*', 'g'), '</$1>\n'); |
9 | 420 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
// Indent <li>, <dt> and <dd> tags. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
html = html.replace(/<((li|dt|dd)[^>]*)>/g, ' \t<$1>'); |
9 | 423 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
// Fix line breaks around <select> and <option>. |
9 | 425 |
if (html.indexOf('<option') !== -1) { |
426 |
html = html.replace(/\s*<option/g, '\n<option'); |
|
427 |
html = html.replace(/\s*<\/select>/g, '\n</select>'); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
} |
9 | 429 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
430 |
// Pad <hr> with two line breaks. |
9 | 431 |
if (html.indexOf('<hr') !== -1) { |
432 |
html = html.replace(/\s*<hr( [^>]*)?>\s*/g, '\n\n<hr$1>\n\n'); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
433 |
} |
9 | 434 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
435 |
// Remove line breaks in <object> tags. |
9 | 436 |
if (html.indexOf('<object') !== -1) { |
18 | 437 |
html = html.replace(/<object[\s\S]+?<\/object>/g, a => { |
9 | 438 |
return a.replace(/[\r\n]+/g, ''); |
439 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
440 |
} |
9 | 441 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
442 |
// Unmark special paragraph closing tags. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
443 |
html = html.replace(/<\/p#>/g, '</p>\n'); |
9 | 444 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
445 |
// Pad remaining <p> tags whit a line break. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
446 |
html = html.replace(/\s*(<p [^>]+>[\s\S]*?<\/p>)/g, '\n$1'); |
9 | 447 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
448 |
// Trim. |
9 | 449 |
html = html.replace(/^\s+/, ''); |
450 |
html = html.replace(/[\s\u00a0]+$/, ''); |
|
451 |
if (preserveLinebreaks) { |
|
452 |
html = html.replace(/<wp-line-break>/g, '\n'); |
|
453 |
} |
|
454 |
if (preserveBr) { |
|
455 |
html = html.replace(/<wp-temp-br([^>]*)>/g, '<br$1>'); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
456 |
} |
9 | 457 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
458 |
// Restore preserved tags. |
9 | 459 |
if (preserve.length) { |
18 | 460 |
html = html.replace(/<wp-preserve>/g, () => { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
461 |
return /** @type {string} */preserve.shift(); |
9 | 462 |
}); |
463 |
} |
|
464 |
return html; |
|
465 |
} |
|
466 |
||
19 | 467 |
(window.wp = window.wp || {}).autop = __webpack_exports__; |
468 |
/******/ })() |
|
469 |
; |