Fix creating of extra `<br />` tags in both PHP and JS variants of wpautop(). Add PHP tests to catch similar problems in the future.
Props valendesigns, azaozz. Fixes #33377. Built from https://develop.svn.wordpress.org/trunk@33624 git-svn-id: http://core.svn.wordpress.org/trunk@33591 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
50e42e8a07
commit
2de7757124
|
@ -272,7 +272,13 @@
|
||||||
text = text.replace( /<\/blockquote>\s*<\/p>/gi, '</p></blockquote>');
|
text = text.replace( /<\/blockquote>\s*<\/p>/gi, '</p></blockquote>');
|
||||||
text = text.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '$1' );
|
text = text.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '$1' );
|
||||||
text = text.replace( new RegExp( '(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), '$1' );
|
text = text.replace( new RegExp( '(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), '$1' );
|
||||||
text = text.replace( /\s*\n/gi, '<br />\n');
|
|
||||||
|
// Remove redundant spaces and line breaks after existing <br /> tags
|
||||||
|
text = text.replace( /(<br[^>]*>)\s*\n/gi, '$1' );
|
||||||
|
|
||||||
|
// Create <br /> from the remaining line breaks
|
||||||
|
text = text.replace( /\s*\n/g, '<br />\n');
|
||||||
|
|
||||||
text = text.replace( new RegExp( '(</?(?:' + blocklist + ')[^>]*>)\\s*<br />', 'gi' ), '$1' );
|
text = text.replace( new RegExp( '(</?(?:' + blocklist + ')[^>]*>)\\s*<br />', 'gi' ), '$1' );
|
||||||
text = text.replace( /<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1' );
|
text = text.replace( /<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1' );
|
||||||
text = text.replace( /(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]' );
|
text = text.replace( /(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]' );
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -491,7 +491,7 @@ function wpautop( $pee, $br = true ) {
|
||||||
$pee .= $last_pee;
|
$pee .= $last_pee;
|
||||||
}
|
}
|
||||||
// Change multiple <br>s into two line breaks, which will turn into paragraphs.
|
// Change multiple <br>s into two line breaks, which will turn into paragraphs.
|
||||||
$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
|
$pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
|
||||||
|
|
||||||
$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)';
|
$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)';
|
||||||
|
|
||||||
|
@ -574,6 +574,9 @@ function wpautop( $pee, $br = true ) {
|
||||||
// Replace newlines that shouldn't be touched with a placeholder.
|
// Replace newlines that shouldn't be touched with a placeholder.
|
||||||
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
|
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
|
||||||
|
|
||||||
|
// Normalize <br>
|
||||||
|
$pee = str_replace( array( '<br>', '<br/>' ), '<br />', $pee );
|
||||||
|
|
||||||
// Replace any new line characters that aren't preceded by a <br /> with a <br />.
|
// Replace any new line characters that aren't preceded by a <br /> with a <br />.
|
||||||
$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
|
$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.3-RC2-33623';
|
$wp_version = '4.3-RC2-33624';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue