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);