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