WordPress.org

Make WordPress Core

Changeset 106


Ignore:
Timestamp:
05/26/2003 11:44:05 AM (16 years ago)
Author:
saxmatt
Message:

Much improved (and faster!) autop.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/b2-include/b2functions.php

    r69 r106  
    100100
    101101function wpautop($pee, $br=1) {
    102     $pee = preg_replace("/(\r\n|\n|\r)/", "\n", $pee); // cross-platform newlines
    103     $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    104     $pee = preg_replace('/\n?(.+?)(\n\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end
    105     $pee = preg_replace('/<p>\s*(<(?:table|ol|ul|pre|select|form)>)/', "$1", $pee);
    106     $pee = preg_replace('!(</(?:table|ol|ul|pre|select|form)>)</p>!', "$1", $pee);
    107     if ($br) $pee = preg_replace('|(?<!</p>)\s*\n|', "<br />\n", $pee); // optionally make line breaks
    108     $pee = preg_replace('!(</?(?:table|ul|ol|li|pre|select|form|blockquote)>)<br />!', "$1", $pee);
    109     $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
    110     $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    111     $pee = str_replace('<p><p>', '<p>', $pee);
    112     $pee = preg_replace('#</p>\s*</p>#', '</p>', $pee);
    113     $pee = preg_replace('/&[^#](?![a-z]*;)/', '&#038;', $pee);
    114     return $pee;
     102    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
     103    $pee = preg_replace("/(\r\n|\n|\r)/", "\n", $pee); // cross-platform newlines
     104    $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
     105    $pee = preg_replace('/\n?(.+?)(\n\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end
     106    $pee = str_replace('<br /></p>', '</p>', $pee);
     107    $pee = str_replace('<p><p>', '<p>', $pee);
     108    $pee = str_replace('</p></p>', '</p>', $pee);
     109    $pee = preg_replace('!<p>\s*(</?(?:table|ul|ol|li|pre|select|form|blockquote)>)!', "$1", $pee);
     110    $pee = preg_replace('!(</?(?:table|ul|ol|li|pre|select|form|blockquote)>)\s*</p>!', "$1", $pee);
     111    if ($br) $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
     112    $pee = preg_replace('!(</?(?:table|ul|ol|li|pre|select|form|blockquote|p)>)<br />!', "$1", $pee);
     113    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
     114    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
     115    return $pee;
    115116}
    116117
Note: See TracChangeset for help on using the changeset viewer.