WordPress.org

Make WordPress Core

Changeset 40091


Ignore:
Timestamp:
02/21/17 03:41:42 (8 months ago)
Author:
dd32
Message:

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.

Location:
branches/4.7
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-admin/js/editor.js

    r38594 r40091  
    119119        // Replace paragraphs with double line breaks 
    120120        function removep( html ) { 
    121             var blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset', 
     121            var blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset|figure', 
    122122                blocklist1 = blocklist + '|div|p', 
    123123                blocklist2 = blocklist + '|pre', 
     
    256256                    return a.replace( /\n/g, '<wp-line-break>' ); 
    257257                }); 
     258            } 
     259 
     260            if ( text.indexOf( '<figcaption' ) !== -1 ) { 
     261                text = text.replace( /\s*(<figcaption[^>]*>)/g, '$1' ); 
     262                text = text.replace( /<\/figcaption>\s*/g, '</figcaption>' ); 
    258263            } 
    259264 
  • branches/4.7/src/wp-includes/formatting.php

    r39326 r40091  
    505505        $pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee ); 
    506506        $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee ); 
     507    } 
     508 
     509    // Collapse line breaks before and after <figcaption> elements. 
     510    if ( strpos( $pee, '<figcaption' ) !== false ) { 
     511        $pee = preg_replace( '|\s*(<figcaption[^>]*>)|', '$1', $pee ); 
     512        $pee = preg_replace( '|</figcaption>\s*|', '</figcaption>', $pee ); 
    507513    } 
    508514 
  • branches/4.7/tests/phpunit/tests/formatting/Autop.php

    r38592 r40091  
    535535        $this->assertEquals( $expected, trim( wpautop( $content ) ) ); 
    536536    } 
     537 
     538    /** 
     539     * wpautop() should not add extra </p> before <figcaption> 
     540     * 
     541     * @covers ::wpautop 
     542     * @uses trim 
     543     * 
     544     * @ticket 39307 
     545     */ 
     546    function test_that_wpautop_doses_not_add_extra_closing_p_in_figure() { 
     547        $content1 = $expected1 = '<figure><img src="example.jpg" /><figcaption>Caption</figcaption></figure>'; 
     548 
     549        $content2 = '<figure> 
     550<img src="example.jpg" /> 
     551<figcaption>Caption</figcaption> 
     552</figure>'; 
     553 
     554        $expected2 = '<figure> 
     555<img src="example.jpg" /><figcaption>Caption</figcaption></figure>'; 
     556 
     557        $this->assertEquals( $expected1, trim( wpautop( $content1 ) ) ); 
     558        $this->assertEquals( $expected2, trim( wpautop( $content2 ) ) ); 
     559    } 
     560 
    537561} 
Note: See TracChangeset for help on using the changeset viewer.