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