Formatting: fix `wpautop()` to stop adding paragraph tags around `<figcaption>`.

Fixes #39307 for trunk.

git-svn-id: https://develop.svn.wordpress.org/trunk@39912 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2017-01-16 01:05:33 +00:00
parent f8cc0fda44
commit 14e5a08f5c
2 changed files with 12 additions and 1 deletions

View File

@ -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( '<figcaption' ) !== -1 ) {
text = text.replace( /\s*(<figcaption[^>]*>)/g, '$1' );
text = text.replace( /<\/figcaption>\s*/g, '</figcaption>' );
}
// Keep <br> tags inside captions.
if ( text.indexOf( '[caption' ) !== -1 ) {
preserve_br = true;

View File

@ -506,6 +506,12 @@ function wpautop( $pee, $br = true ) {
$pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee );
}
// Collapse line breaks before and after <figcaption> elements.
if ( strpos( $pee, '<figcaption' ) !== false ) {
$pee = preg_replace( '|\s*(<figcaption[^>]*>)|', '$1', $pee );
$pee = preg_replace( '|</figcaption>\s*|', '</figcaption>', $pee );
}
// Remove more than two contiguous line breaks.
$pee = preg_replace("/\n\n+/", "\n\n", $pee);