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