WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/05/2014 12:45:53 AM (7 years ago)
Author:
azaozz
Message:

Consolidate handling of <object>, <audio> and <video> in wpautop() and add unit tests for them. Part props wonderboymusic, see #26864

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r27042 r27094  
    239239    $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
    240240    $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
    241     if ( strpos($pee, '<object') !== false ) {
    242         $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed
    243         $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    244     }
     241
     242    if ( strpos( $pee, '</object>' ) !== false ) {
     243        // no P/BR around param and embed
     244        $pee = preg_replace( '|(<object[^>]*>)\s*|', '$1', $pee );
     245        $pee = preg_replace( '|\s*</object>|', '</object>', $pee );
     246        $pee = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee );
     247    }
     248
     249    if ( strpos( $pee, '<source' ) !== false || strpos( $pee, '<track' ) !== false ) {
     250        // no P/BR around source and track
     251        $pee = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee );
     252        $pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee );
     253        $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee );
     254    }
     255
    245256    $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    246257    // make paragraphs, including one at the end
    247258    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    248259    $pee = '';
    249     foreach ( $pees as $tinkle )
     260
     261    foreach ( $pees as $tinkle ) {
    250262        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
     263    }
     264
    251265    $pee = preg_replace('|<p>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
    252266    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
     
    257271    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
    258272    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
     273
    259274    if ( $br ) {
    260275        $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
     
    262277        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    263278    }
     279
    264280    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
    265281    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
Note: See TracChangeset for help on using the changeset viewer.