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