wpautop

The timeline below displays how wordpress function wpautop has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Replaces double line breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line breaks with HTML paragraph tags. The remaining line breaks
 * after conversion become `<br />` tags, unless `$br` is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $text The text which has to be formatted.
 * @param bool   $br   Optional. If set, this will convert all remaining line breaks
 *                     after paragraphing. Line breaks within `<script>`, `<style>`,
 *                     and `<svg>` tags are not affected. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($text, $br = true)
{
    $pre_tags = array();
    if (trim($text) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $text = $text . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (str_contains($text, '<pre')) {
        $text_parts = explode('</pre>', $text);
        $last_part = array_pop($text_parts);
        $text = '';
        $i = 0;
        foreach ($text_parts as $text_part) {
            $start = strpos($text_part, '<pre');
            // Malformed HTML?
            if (false === $start) {
                $text .= $text_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($text_part, $start) . '</pre>';
            $text .= substr($text_part, 0, $start) . $name;
            ++$i;
        }
        $text .= $last_part;
    }
    // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
    $text = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $text);
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $text = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $text);
    // Add a double line break below block-level closing tags.
    $text = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $text);
    // Add a double line break after hr tags, which are self closing.
    $text = preg_replace('!(<hr\s*?/?>)!', "\$1\n\n", $text);
    // Standardize newline characters to "\n".
    $text = str_replace(array("\r\n", "\r"), "\n", $text);
    // Find newlines in all elements and add placeholders.
    $text = wp_replace_in_html_tags($text, array("\n" => ' <!-- wpnl --> '));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (str_contains($text, '<option')) {
        $text = preg_replace('|\s*<option|', '<option', $text);
        $text = preg_replace('|</option>\s*|', '</option>', $text);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (str_contains($text, '</object>')) {
        $text = preg_replace('|(<object[^>]*>)\s*|', '$1', $text);
        $text = preg_replace('|\s*</object>|', '</object>', $text);
        $text = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $text);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (str_contains($text, '<source') || str_contains($text, '<track')) {
        $text = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $text);
        $text = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $text);
        $text = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $text);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (str_contains($text, '<figcaption')) {
        $text = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $text);
        $text = preg_replace('|</figcaption>\s*|', '</figcaption>', $text);
    }
    // Remove more than two contiguous line breaks.
    $text = preg_replace("/\n\n+/", "\n\n", $text);
    // Split up the contents into an array of strings, separated by double line breaks.
    $paragraphs = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $text prior to rebuilding.
    $text = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($paragraphs as $paragraph) {
        $text .= '<p>' . trim($paragraph, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $text = preg_replace('|<p>\s*</p>|', '', $text);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $text = preg_replace('!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $text);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text);
    // In some cases <li> may get wrapped in <p>, fix them.
    $text = preg_replace('|<p>(<li.+?)</p>|', '$1', $text);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $text = preg_replace('|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $text);
    $text = str_replace('</blockquote></p>', '</p></blockquote>', $text);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $text);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $text = preg_replace_callback('/<(script|style|svg|math).*?<\/\1>/s', '_autop_newline_preservation_helper', $text);
        // Normalize <br>
        $text = str_replace(array('<br>', '<br/>'), '<br />', $text);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $text = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $text);
        // Replace newline placeholders with newlines.
        $text = str_replace('<WPPreserveNewline />', "\n", $text);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $text);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $text = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $text);
    $text = preg_replace("|\n</p>\$|", '</p>', $text);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $text = str_replace(array_keys($pre_tags), array_values($pre_tags), $text);
    }
    // Restore newlines in all elements.
    if (str_contains($text, '<!-- wpnl -->')) {
        $text = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $text);
    }
    return $text;
}

WordPress Version: 6.3

/**
 * Replaces double line breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line breaks with HTML paragraph tags. The remaining line breaks
 * after conversion become `<br />` tags, unless `$br` is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $text The text which has to be formatted.
 * @param bool   $br   Optional. If set, this will convert all remaining line breaks
 *                     after paragraphing. Line breaks within `<script>`, `<style>`,
 *                     and `<svg>` tags are not affected. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($text, $br = true)
{
    $pre_tags = array();
    if (trim($text) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $text = $text . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (str_contains($text, '<pre')) {
        $text_parts = explode('</pre>', $text);
        $last_part = array_pop($text_parts);
        $text = '';
        $i = 0;
        foreach ($text_parts as $text_part) {
            $start = strpos($text_part, '<pre');
            // Malformed HTML?
            if (false === $start) {
                $text .= $text_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($text_part, $start) . '</pre>';
            $text .= substr($text_part, 0, $start) . $name;
            $i++;
        }
        $text .= $last_part;
    }
    // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
    $text = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $text);
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $text = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $text);
    // Add a double line break below block-level closing tags.
    $text = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $text);
    // Add a double line break after hr tags, which are self closing.
    $text = preg_replace('!(<hr\s*?/?>)!', "\$1\n\n", $text);
    // Standardize newline characters to "\n".
    $text = str_replace(array("\r\n", "\r"), "\n", $text);
    // Find newlines in all elements and add placeholders.
    $text = wp_replace_in_html_tags($text, array("\n" => ' <!-- wpnl --> '));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (str_contains($text, '<option')) {
        $text = preg_replace('|\s*<option|', '<option', $text);
        $text = preg_replace('|</option>\s*|', '</option>', $text);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (str_contains($text, '</object>')) {
        $text = preg_replace('|(<object[^>]*>)\s*|', '$1', $text);
        $text = preg_replace('|\s*</object>|', '</object>', $text);
        $text = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $text);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (str_contains($text, '<source') || str_contains($text, '<track')) {
        $text = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $text);
        $text = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $text);
        $text = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $text);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (str_contains($text, '<figcaption')) {
        $text = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $text);
        $text = preg_replace('|</figcaption>\s*|', '</figcaption>', $text);
    }
    // Remove more than two contiguous line breaks.
    $text = preg_replace("/\n\n+/", "\n\n", $text);
    // Split up the contents into an array of strings, separated by double line breaks.
    $paragraphs = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $text prior to rebuilding.
    $text = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($paragraphs as $paragraph) {
        $text .= '<p>' . trim($paragraph, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $text = preg_replace('|<p>\s*</p>|', '', $text);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $text = preg_replace('!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $text);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text);
    // In some cases <li> may get wrapped in <p>, fix them.
    $text = preg_replace('|<p>(<li.+?)</p>|', '$1', $text);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $text = preg_replace('|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $text);
    $text = str_replace('</blockquote></p>', '</p></blockquote>', $text);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $text);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $text = preg_replace_callback('/<(script|style|svg|math).*?<\/\1>/s', '_autop_newline_preservation_helper', $text);
        // Normalize <br>
        $text = str_replace(array('<br>', '<br/>'), '<br />', $text);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $text = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $text);
        // Replace newline placeholders with newlines.
        $text = str_replace('<WPPreserveNewline />', "\n", $text);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $text);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $text = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $text);
    $text = preg_replace("|\n</p>\$|", '</p>', $text);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $text = str_replace(array_keys($pre_tags), array_values($pre_tags), $text);
    }
    // Restore newlines in all elements.
    if (str_contains($text, '<!-- wpnl -->')) {
        $text = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $text);
    }
    return $text;
}

WordPress Version: 6.2

/**
 * Replaces double line breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line breaks with HTML paragraph tags. The remaining line breaks
 * after conversion become `<br />` tags, unless `$br` is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $text The text which has to be formatted.
 * @param bool   $br   Optional. If set, this will convert all remaining line breaks
 *                     after paragraphing. Line breaks within `<script>`, `<style>`,
 *                     and `<svg>` tags are not affected. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($text, $br = true)
{
    $pre_tags = array();
    if (trim($text) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $text = $text . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($text, '<pre') !== false) {
        $text_parts = explode('</pre>', $text);
        $last_part = array_pop($text_parts);
        $text = '';
        $i = 0;
        foreach ($text_parts as $text_part) {
            $start = strpos($text_part, '<pre');
            // Malformed HTML?
            if (false === $start) {
                $text .= $text_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($text_part, $start) . '</pre>';
            $text .= substr($text_part, 0, $start) . $name;
            $i++;
        }
        $text .= $last_part;
    }
    // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
    $text = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $text);
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $text = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $text);
    // Add a double line break below block-level closing tags.
    $text = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $text);
    // Add a double line break after hr tags, which are self closing.
    $text = preg_replace('!(<hr\s*?/?>)!', "\$1\n\n", $text);
    // Standardize newline characters to "\n".
    $text = str_replace(array("\r\n", "\r"), "\n", $text);
    // Find newlines in all elements and add placeholders.
    $text = wp_replace_in_html_tags($text, array("\n" => ' <!-- wpnl --> '));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($text, '<option') !== false) {
        $text = preg_replace('|\s*<option|', '<option', $text);
        $text = preg_replace('|</option>\s*|', '</option>', $text);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($text, '</object>') !== false) {
        $text = preg_replace('|(<object[^>]*>)\s*|', '$1', $text);
        $text = preg_replace('|\s*</object>|', '</object>', $text);
        $text = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $text);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($text, '<source') !== false || strpos($text, '<track') !== false) {
        $text = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $text);
        $text = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $text);
        $text = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $text);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (strpos($text, '<figcaption') !== false) {
        $text = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $text);
        $text = preg_replace('|</figcaption>\s*|', '</figcaption>', $text);
    }
    // Remove more than two contiguous line breaks.
    $text = preg_replace("/\n\n+/", "\n\n", $text);
    // Split up the contents into an array of strings, separated by double line breaks.
    $paragraphs = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $text prior to rebuilding.
    $text = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($paragraphs as $paragraph) {
        $text .= '<p>' . trim($paragraph, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $text = preg_replace('|<p>\s*</p>|', '', $text);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $text = preg_replace('!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $text);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text);
    // In some cases <li> may get wrapped in <p>, fix them.
    $text = preg_replace('|<p>(<li.+?)</p>|', '$1', $text);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $text = preg_replace('|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $text);
    $text = str_replace('</blockquote></p>', '</p></blockquote>', $text);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $text);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $text = preg_replace_callback('/<(script|style|svg|math).*?<\/\1>/s', '_autop_newline_preservation_helper', $text);
        // Normalize <br>
        $text = str_replace(array('<br>', '<br/>'), '<br />', $text);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $text = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $text);
        // Replace newline placeholders with newlines.
        $text = str_replace('<WPPreserveNewline />', "\n", $text);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $text);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $text = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $text);
    $text = preg_replace("|\n</p>\$|", '</p>', $text);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $text = str_replace(array_keys($pre_tags), array_values($pre_tags), $text);
    }
    // Restore newlines in all elements.
    if (false !== strpos($text, '<!-- wpnl -->')) {
        $text = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $text);
    }
    return $text;
}

WordPress Version: 6.1

/**
 * Replaces double line breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line breaks with HTML paragraph tags. The remaining line breaks
 * after conversion become `<br />` tags, unless `$br` is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $text The text which has to be formatted.
 * @param bool   $br   Optional. If set, this will convert all remaining line breaks
 *                     after paragraphing. Line breaks within `<script>`, `<style>`,
 *                     and `<svg>` tags are not affected. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($text, $br = true)
{
    $pre_tags = array();
    if (trim($text) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $text = $text . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($text, '<pre') !== false) {
        $text_parts = explode('</pre>', $text);
        $last_part = array_pop($text_parts);
        $text = '';
        $i = 0;
        foreach ($text_parts as $text_part) {
            $start = strpos($text_part, '<pre');
            // Malformed HTML?
            if (false === $start) {
                $text .= $text_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($text_part, $start) . '</pre>';
            $text .= substr($text_part, 0, $start) . $name;
            $i++;
        }
        $text .= $last_part;
    }
    // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
    $text = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $text);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $text = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $text);
    // Add a double line break below block-level closing tags.
    $text = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $text);
    // Add a double line break after hr tags, which are self closing.
    $text = preg_replace('!(<hr\s*?/?>)!', "\$1\n\n", $text);
    // Standardize newline characters to "\n".
    $text = str_replace(array("\r\n", "\r"), "\n", $text);
    // Find newlines in all elements and add placeholders.
    $text = wp_replace_in_html_tags($text, array("\n" => ' <!-- wpnl --> '));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($text, '<option') !== false) {
        $text = preg_replace('|\s*<option|', '<option', $text);
        $text = preg_replace('|</option>\s*|', '</option>', $text);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($text, '</object>') !== false) {
        $text = preg_replace('|(<object[^>]*>)\s*|', '$1', $text);
        $text = preg_replace('|\s*</object>|', '</object>', $text);
        $text = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $text);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($text, '<source') !== false || strpos($text, '<track') !== false) {
        $text = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $text);
        $text = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $text);
        $text = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $text);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (strpos($text, '<figcaption') !== false) {
        $text = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $text);
        $text = preg_replace('|</figcaption>\s*|', '</figcaption>', $text);
    }
    // Remove more than two contiguous line breaks.
    $text = preg_replace("/\n\n+/", "\n\n", $text);
    // Split up the contents into an array of strings, separated by double line breaks.
    $paragraphs = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $text prior to rebuilding.
    $text = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($paragraphs as $paragraph) {
        $text .= '<p>' . trim($paragraph, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $text = preg_replace('|<p>\s*</p>|', '', $text);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $text = preg_replace('!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $text);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text);
    // In some cases <li> may get wrapped in <p>, fix them.
    $text = preg_replace('|<p>(<li.+?)</p>|', '$1', $text);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $text = preg_replace('|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $text);
    $text = str_replace('</blockquote></p>', '</p></blockquote>', $text);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $text = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $text);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $text = preg_replace_callback('/<(script|style|svg).*?<\/\1>/s', '_autop_newline_preservation_helper', $text);
        // Normalize <br>
        $text = str_replace(array('<br>', '<br/>'), '<br />', $text);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $text = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $text);
        // Replace newline placeholders with newlines.
        $text = str_replace('<WPPreserveNewline />', "\n", $text);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $text = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $text);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $text = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $text);
    $text = preg_replace("|\n</p>\$|", '</p>', $text);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $text = str_replace(array_keys($pre_tags), array_values($pre_tags), $text);
    }
    // Restore newlines in all elements.
    if (false !== strpos($text, '<!-- wpnl -->')) {
        $text = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $text);
    }
    return $text;
}

WordPress Version: 5.5

/**
 * Replaces double line breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line breaks with HTML paragraph tags. The remaining line breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line breaks
 *                    after paragraphing. Line breaks within `<script>`, `<style>`,
 *                    and `<svg>` tags are not affected. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed HTML?
            if (false === $start) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Add a double line break after hr tags, which are self closing.
    $pee = preg_replace('!(<hr\s*?/?>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => ' <!-- wpnl --> '));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (strpos($pee, '<figcaption') !== false) {
        $pee = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $pee);
        $pee = preg_replace('|</figcaption>\s*|', '</figcaption>', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace('|<p>(<li.+?)</p>|', '$1', $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style|svg).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    if (false !== strpos($pee, '<!-- wpnl -->')) {
        $pee = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $pee);
    }
    return $pee;
}

WordPress Version: 5.4

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed HTML?
            if (false === $start) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Add a double line break after hr tags, which are self closing.
    $pee = preg_replace('!(<hr\s*?/?>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => ' <!-- wpnl --> '));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (strpos($pee, '<figcaption') !== false) {
        $pee = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $pee);
        $pee = preg_replace('|</figcaption>\s*|', '</figcaption>', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace('|<p>(<li.+?)</p>|', '$1', $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style|svg).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    if (false !== strpos($pee, '<!-- wpnl -->')) {
        $pee = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $pee);
    }
    return $pee;
}

WordPress Version: 5.3

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Add a double line break after hr tags, which are self closing.
    $pee = preg_replace('!(<hr\s*?/?>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => ' <!-- wpnl --> '));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (strpos($pee, '<figcaption') !== false) {
        $pee = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $pee);
        $pee = preg_replace('|</figcaption>\s*|', '</figcaption>', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace('|<p>(<li.+?)</p>|', '$1', $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style|svg).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    if (false !== strpos($pee, '<!-- wpnl -->')) {
        $pee = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $pee);
    }
    return $pee;
}

WordPress Version: 5.1

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => ' <!-- wpnl --> '));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (strpos($pee, '<figcaption') !== false) {
        $pee = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $pee);
        $pee = preg_replace('|</figcaption>\s*|', '</figcaption>', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace('|<p>(<li.+?)</p>|', '$1', $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    if (false !== strpos($pee, '<!-- wpnl -->')) {
        $pee = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $pee);
    }
    return $pee;
}

WordPress Version: 7.3

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Collapse line breaks before and after <figcaption> elements.
    if (strpos($pee, '<figcaption') !== false) {
        $pee = preg_replace('|\s*(<figcaption[^>]*>)|', '$1', $pee);
        $pee = preg_replace('|</figcaption>\s*|', '</figcaption>', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    if (false !== strpos($pee, '<!-- wpnl -->')) {
        $pee = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $pee);
    }
    return $pee;
}

WordPress Version: 4.7

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a double line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    if (false !== strpos($pee, '<!-- wpnl -->')) {
        $pee = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $pee);
    }
    return $pee;
}

WordPress Version: 4.4

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    if (false !== strpos($pee, '<!-- wpnl -->')) {
        $pee = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $pee);
    }
    return $pee;
}

WordPress Version: 3.1

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    if (false !== strpos($pee, '<!-- wpnl -->')) {
        $pee = str_replace(array(' <!-- wpnl --> ', '<!-- wpnl -->'), "\n", $pee);
    }
    return $pee;
}

WordPress Version: 4.3

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Normalize <br>
        $pee = str_replace(array('<br>', '<br/>'), '<br />', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: .30

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 2.3

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Strip newlines from all elements.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .20

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 2.2

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .10

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 4.2

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
 *                    after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    // Just to make things a little easier, pad the end.
    $pee = $pee . "\n";
    /*
     * Pre tags shouldn't be touched by autop.
     * Replace pre tags with placeholders and bring them back after autop.
     */
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    // Change multiple <br>s into two line breaks, which will turn into paragraphs.
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    // Add a single line break above block-level opening tags.
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    // Add a double line break below block-level closing tags.
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    // Standardize newline characters to "\n".
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    if (strpos($pee, '<option') !== false) {
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    /*
     * Collapse line breaks inside <object> elements, before <param> and <embed> elements
     * so they don't get autop'd.
     */
    if (strpos($pee, '</object>') !== false) {
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    /*
     * Collapse line breaks inside <audio> and <video> elements,
     * before and after <source> and <track> elements.
     */
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    // Remove more than two contiguous line breaks.
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // Split up the contents into an array of strings, separated by double line breaks.
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    // Reset $pee prior to rebuilding.
    $pee = '';
    // Rebuild the content as a string, wrapping every bit with a <p>.
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    // Under certain strange conditions it could create a P of entirely whitespace.
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // In some cases <li> may get wrapped in <p>, fix them.
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // Optionally insert line breaks.
    if ($br) {
        // Replace newlines that shouldn't be touched with a placeholder.
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // Replace newline placeholders with newlines.
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    // If a <br /> tag is after an opening or closing block tag, remove it.
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    // Replace placeholder <pre> tags with their original content.
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 1.7

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 1.6

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Strip newlines from all elements.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 1.5

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .40

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 1.4

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .30

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 1.3

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .20

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 1.2

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .10

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 4.1

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 0.7

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 0.6

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Strip newlines from all elements.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 0.4

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .30

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 0.3

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .20

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 0.2

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .10

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 4.0

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<option') !== false) {
        // no P/BR around option
        $pee = preg_replace('|\s*<option|', '<option', $pee);
        $pee = preg_replace('|</option>\s*|', '</option>', $pee);
    }
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 9.8

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 9.7

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Strip newlines from all elements.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " "));
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 9.2

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .10

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 3.9

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $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)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '</object>') !== false) {
        // no P/BR around param and embed
        $pee = preg_replace('|(<object[^>]*>)\s*|', '$1', $pee);
        $pee = preg_replace('|\s*</object>|', '</object>', $pee);
        $pee = preg_replace('%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee);
    }
    if (strpos($pee, '<source') !== false || strpos($pee, '<track') !== false) {
        // no P/BR around source and track
        $pee = preg_replace('%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee);
        $pee = preg_replace('%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee);
        $pee = preg_replace('%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 8.9

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Strip newlines from all elements.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 8.4

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .30

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 8.3

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .20

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 8.2

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .10

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 3.8

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 7.9

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Strip newlines from all elements.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: 7.5

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .40

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 7.4

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .30

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 7.3

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .20

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 7.2

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}

WordPress Version: .10

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    // Find newlines in all elements and add placeholders.
    $pee = wp_replace_in_html_tags($pee, array("\n" => " <!-- wpnl --> "));
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    // Restore newlines in all elements.
    $pee = str_replace(" <!-- wpnl --> ", "\n", $pee);
    return $pee;
}

WordPress Version: 3.7

/**
 * Replaces double line-breaks with paragraph elements.
 *
 * A group of regex replaces used to identify text formatted with newlines and
 * replace double line-breaks with HTML paragraph tags. The remaining
 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
 * or 'false'.
 *
 * @since 0.71
 *
 * @param string $pee The text which has to be formatted.
 * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
 * @return string Text which has been converted into correct paragraph tags.
 */
function wpautop($pee, $br = true)
{
    $pre_tags = array();
    if (trim($pee) === '') {
        return '';
    }
    $pee = $pee . "\n";
    // just to make things a little easier, pad the end
    if (strpos($pee, '<pre') !== false) {
        $pee_parts = explode('</pre>', $pee);
        $last_pee = array_pop($pee_parts);
        $pee = '';
        $i = 0;
        foreach ($pee_parts as $pee_part) {
            $start = strpos($pee_part, '<pre');
            // Malformed html?
            if ($start === false) {
                $pee .= $pee_part;
                continue;
            }
            $name = "<pre wp-pre-tag-{$i}></pre>";
            $pre_tags[$name] = substr($pee_part, $start) . '</pre>';
            $pee .= substr($pee_part, 0, $start) . $name;
            $i++;
        }
        $pee .= $last_pee;
    }
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "\$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    // cross-platform newlines
    if (strpos($pee, '<object') !== false) {
        $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param\$1>", $pee);
        // no pee inside object/embed
        $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee);
    // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ($pees as $tinkle) {
        $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    }
    $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    // under certain strange conditions it could create a P of entirely whitespace
    $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>\$1</p></\$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "\$1", $pee);
    // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote\$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "\$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "\$1", $pee);
    if ($br) {
        $pee = preg_replace_callback('/<(script|style).*?<\/\1>/s', '_autop_newline_preservation_helper', $pee);
        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
        // optionally make line breaks
        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "\$1", $pee);
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    $pee = preg_replace("|\n</p>\$|", '</p>', $pee);
    if (!empty($pre_tags)) {
        $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    }
    return $pee;
}