WordPress.org

Make WordPress Core

Ticket #18330: wpautop.patch

File wpautop.patch, 2.3 KB (added by wpsmith, 7 years ago)
  • formatting.php

     
    167167 * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
    168168 * @return string Text which has been converted into correct paragraph tags.
    169169 */
    170 function wpautop($pee, $br = 1) {
    171 
     170function wpautop($pee, $br = 1, $class = '') {
     171        $class = ( $class ) ? ' class="'.$class.'"' : '';
    172172        if ( trim($pee) === '' )
    173173                return '';
    174174        $pee = $pee . "\n"; // just to make things a little easier, pad the end
     
    187187        $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    188188        $pee = '';
    189189        foreach ( $pees as $tinkle )
    190                 $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    191         $pee = preg_replace('|<p>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
    192         $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
    193         $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
    194         $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
    195         $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
     190                $pee .= '<p'.$class.'>' . trim($tinkle, "\n") . "</p>\n";
     191        $pee = preg_replace('|<p'.$class.'>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
     192        $pee = preg_replace('!<p'.$class.'>([^<]+)</(div|address|form)>!', "<p".$class.">$1</p></$2>", $pee);
     193        $pee = preg_replace('!<p'.$class.'>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
     194        $pee = preg_replace("|<p'.$class.'>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
     195        $pee = preg_replace('|<p'.$class.'><blockquote([^>]*)>|i', "<blockquote$1><p ".$class.">", $pee);
    196196        $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    197         $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
     197        $pee = preg_replace('!<p'.$class.'>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
    198198        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
    199199        if ($br) {
    200200                $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);