Make WordPress Core

Ticket #15367: 15367_formatting_wpautop.patch

File 15367_formatting_wpautop.patch, 2.0 KB (added by TomAuger, 13 years ago)

Modified wpautop in formatting.php

  • formatting.php

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: C:\xampp\htdocs\wordpress\sandbox\wp-includes
    # This patch can be applied using context Tools: Patch action on respective folder.
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    178178        $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
    179179        $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
    180180        $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
     181
     182        // Pull out any PRE tags so they're not affected at all
     183        $pres = array();
     184        if ( strpos($pee, '<pre') !== false ){
     185                preg_match_all( '!<pre[^>]*>.+?</pre>!is', $pee, $pres );
     186                if ( count( $pres ) ){
     187                        $pee = preg_replace( '!<pre[^>]*>.+?</pre>!is', '<WPPreservePre />', $pee );
     188                }
     189        }
     190
    181191        if ( strpos($pee, '<object') !== false ) {
    182192                $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed
    183193                $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
     
    203213        }
    204214        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
    205215        $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    206         if (strpos($pee, '<pre') !== false)
    207                 $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
     216       
     217        // Substitute our preserved PREs back in
     218        if ( count( $pres ) ){
     219                foreach ( $pres as $pre ){
     220                        $pee = preg_replace( '!<WPPreservePre />!', $pre[0], $pee, 1 );
     221                }
     222        }
     223
     224        // We don't need this any more. Better to leave all <pre> content untouched
     225//      if (strpos($pee, '<pre') !== false)
     226//              $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
     227       
    208228        $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
    209229
    210230        return $pee;