]*)>/gi, '');
text = text.replace(/<\/blockquote><\/p>/g, '
');
// If an opening or closing block element tag is preceded by an opening tag, remove it.
text = text.replace(new RegExp('
\\s*(?' + allBlocks + '[^>]*>)', 'g'), '$1');
// If an opening or closing block element tag is followed by a closing
tag, remove it.
text = text.replace(new RegExp('(?' + allBlocks + '[^>]*>)\\s*
', 'g'), '$1');
// Optionally insert line breaks.
if (br) {
// Replace newlines that shouldn't be touched with a placeholder.
text = text.replace(/<(script|style).*?<\/\\1>/g, match => match[0].replace(/\n/g, ''));
// Normalize
text = text.replace(/
|
/g, '
');
// Replace any new line characters that aren't preceded by a
with a
.
text = text.replace(/(
)?\s*\n/g, (a, b) => b ? a : '
\n');
// Replace newline placeholders with newlines.
text = text.replace(//g, '\n');
}
// If a
tag is after an opening or closing block tag, remove it.
text = text.replace(new RegExp('(?' + allBlocks + '[^>]*>)\\s*
', 'g'), '$1');
// If a
tag is before a subset of opening or closing block tags, remove it.
text = text.replace(/
(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)/g, '$1');
text = text.replace(/\n<\/p>$/g, '');
// Replace placeholder tags with their original content.
preTags.forEach(preTag => {
const [name, original] = preTag;
text = text.replace(name, original);
});
// Restore newlines in all elements.
if (-1 !== text.indexOf('')) {
text = text.replace(/\s?\s?/g, '\n');
}
return text;
}
/**
* Replaces `` tags with two line breaks. "Opposite" of autop().
*
* Replaces `
` tags with two line breaks except where the `
` has attributes.
* Unifies whitespace. Indents `
`, `` and `` for better readability.
*
* @param {string} html The content from the editor.
*
* @example
* ```js
* import { removep } from '@wordpress/autop';
* removep( 'my text
' ); // "my text"
* ```
*
* @return {string} The content with stripped paragraph tags.
*/
function removep(html) {
const blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset|figure';
const blocklist1 = blocklist + '|div|p';
const blocklist2 = blocklist + '|pre';
/** @type {string[]} */
const preserve = [];
let preserveLinebreaks = false;
let preserveBr = false;
if (!html) {
return '';
}
// Protect script and style tags.
if (html.indexOf('