WordPress.org

Make WordPress Core

Ticket #27733: 27733.diff

File 27733.diff, 4.1 KB (added by tenpura, 6 years ago)

Replace All \s with [\r\n\t ]

  • wp-includes/formatting.php

     
    275275                $pee .= $last_pee;
    276276        }
    277277
    278         $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
     278        $pee = preg_replace('|<br />[\r\n\t ]*<br />|', "\n\n", $pee);
    279279        // Space things out a little
    280280        $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    281281        $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
     
    284284
    285285        if ( strpos( $pee, '</object>' ) !== false ) {
    286286                // no P/BR around param and embed
    287                 $pee = preg_replace( '|(<object[^>]*>)\s*|', '$1', $pee );
    288                 $pee = preg_replace( '|\s*</object>|', '</object>', $pee );
    289                 $pee = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee );
     287                $pee = preg_replace( '|(<object[^>]*>)[\r\n\t ]*|', '$1', $pee );
     288                $pee = preg_replace( '|[\r\n\t ]*</object>|', '</object>', $pee );
     289                $pee = preg_replace( '%[\r\n\t ]*(</?(?:param|embed)[^>]*>)[\r\n\t ]*%', '$1', $pee );
    290290        }
    291291
    292292        if ( strpos( $pee, '<source' ) !== false || strpos( $pee, '<track' ) !== false ) {
    293293                // no P/BR around source and track
    294                 $pee = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee );
    295                 $pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee );
    296                 $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee );
     294                $pee = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])[\r\n\t ]*%', '$1', $pee );
     295                $pee = preg_replace( '%[\r\n\t ]*([<\[]/(?:audio|video)[>\]])%', '$1', $pee );
     296                $pee = preg_replace( '%[\r\n\t ]*(<(?:source|track)[^>]*>)[\r\n\t ]*%', '$1', $pee );
    297297        }
    298298
    299299        $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    300300        // make paragraphs, including one at the end
    301         $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
     301        $pees = preg_split('/\n[\r\n\t ]*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    302302        $pee = '';
    303303
    304304        foreach ( $pees as $tinkle ) {
    305305                $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    306306        }
    307307
    308         $pee = preg_replace('|<p>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
     308        $pee = preg_replace('|<p>[\r\n\t ]*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
    309309        $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
    310         $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
     310        $pee = preg_replace('!<p>[\r\n\t ]*(</?' . $allblocks . '[^>]*>)[\r\n\t ]*</p>!', "$1", $pee); // don't pee all over a tag
    311311        $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
    312312        $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
    313313        $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    314         $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
    315         $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
     314        $pee = preg_replace('!<p>[\r\n\t ]*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
     315        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)[\r\n\t ]*</p>!', "$1", $pee);
    316316
    317317        if ( $br ) {
    318318                $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
    319                 $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
     319                $pee = preg_replace('|(?<!<br />)[\r\n\t ]*\n|', "<br />\n", $pee); // optionally make line breaks
    320320                $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    321321        }
    322322
    323         $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
    324         $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
     323        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)[\r\n\t ]*<br />!', "$1", $pee);
     324        $pee = preg_replace('!<br />([\r\n\t ]*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    325325        $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
    326326
    327327        if ( !empty($pre_tags) )