From 14e5a08f5c4f742e3dd5905331097dd36653c486 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 16 Jan 2017 01:05:33 +0000 Subject: [PATCH] Formatting: fix `wpautop()` to stop adding paragraph tags around `
`. Fixes #39307 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@39912 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/editor.js | 7 ++++++- src/wp-includes/formatting.php | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/js/editor.js b/src/wp-admin/js/editor.js index 17d296276d..a63a51cc53 100644 --- a/src/wp-admin/js/editor.js +++ b/src/wp-admin/js/editor.js @@ -167,7 +167,7 @@ * @return {string} The content with stripped paragraph tags. */ function removep( html ) { - var blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset', + var blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset|figure', blocklist1 = blocklist + '|div|p', blocklist2 = blocklist + '|pre', preserve_linebreaks = false, @@ -331,6 +331,11 @@ }); } + if ( text.indexOf( ']*>)/g, '$1' ); + text = text.replace( /<\/figcaption>\s*/g, '
' ); + } + // Keep
tags inside captions. if ( text.indexOf( '[caption' ) !== -1 ) { preserve_br = true; diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 31352cdeb2..a57a481ced 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -506,6 +506,12 @@ function wpautop( $pee, $br = true ) { $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee ); } + // Collapse line breaks before and after
elements. + if ( strpos( $pee, ']*>)|', '$1', $pee ); + $pee = preg_replace( '|
\s*|', '', $pee ); + } + // Remove more than two contiguous line breaks. $pee = preg_replace("/\n\n+/", "\n\n", $pee);