@wordpress/autop 4.32.0 → 4.32.1-next.b8c8708f3.0

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