Formatting: fix wpautop()
to stop adding paragraph tags around <figcaption>
.
Props azaozz, pbearne for tests. Merges [39912], [39914] to the 4.7 branch. Fixes #39307 for 4.7. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@40091 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b34712067e
commit
28bcb22f2f
@ -118,7 +118,7 @@
|
||||
|
||||
// Replace paragraphs with double line breaks
|
||||
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,
|
||||
@ -257,6 +257,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 and convert line breaks
|
||||
if ( text.indexOf( '[caption' ) !== -1 ) {
|
||||
preserve_br = true;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -534,4 +534,28 @@ line 2<br/>
|
||||
|
||||
$this->assertEquals( $expected, trim( wpautop( $content ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wpautop() should not add extra </p> before <figcaption>
|
||||
*
|
||||
* @covers ::wpautop
|
||||
* @uses trim
|
||||
*
|
||||
* @ticket 39307
|
||||
*/
|
||||
function test_that_wpautop_doses_not_add_extra_closing_p_in_figure() {
|
||||
$content1 = $expected1 = '<figure><img src="example.jpg" /><figcaption>Caption</figcaption></figure>';
|
||||
|
||||
$content2 = '<figure>
|
||||
<img src="example.jpg" />
|
||||
<figcaption>Caption</figcaption>
|
||||
</figure>';
|
||||
|
||||
$expected2 = '<figure>
|
||||
<img src="example.jpg" /><figcaption>Caption</figcaption></figure>';
|
||||
|
||||
$this->assertEquals( $expected1, trim( wpautop( $content1 ) ) );
|
||||
$this->assertEquals( $expected2, trim( wpautop( $content2 ) ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user