From 08ab6692cf41dc095d4ed6793e7cdbccb6866c33 Mon Sep 17 00:00:00 2001 From: real_nowhereman Date: Thu, 21 Apr 2011 16:35:22 +0000 Subject: [PATCH] import wpautop from wp3 --- fp-includes/core/core.wp-formatting.php | 40 ++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/fp-includes/core/core.wp-formatting.php b/fp-includes/core/core.wp-formatting.php index cfbfcc9..2ef0e69 100644 --- a/fp-includes/core/core.wp-formatting.php +++ b/fp-includes/core/core.wp-formatting.php @@ -75,11 +75,28 @@ return $text; } +/** + * 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 <
> tags, unless $br is set to '0' + * or 'false'. + * + * @since 0.71 + * + * @param string $pee The text which has to be formatted. + * @param int|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 = 1) { + + if ( trim($pee) === '' ) + return ''; $pee = $pee . "\n"; // just to make things a little easier, pad the end $pee = preg_replace('|
\s*
|', "\n\n", $pee); // Space things out a little - $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)'; + $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|input|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); $pee = preg_replace('!()!', "$1\n\n", $pee); $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines @@ -93,9 +110,8 @@ function wpautop($pee, $br = 1) { $pee = ''; foreach ( $pees as $tinkle ) $pee .= '

' . trim($tinkle, "\n") . "

\n"; - $pee = preg_replace('|

\s*?

|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace - $pee = preg_replace('!

([^<]+)\s*?(]*>)!', "

$1

$2", $pee); - $pee = preg_replace( '|

|', "$1

", $pee ); + $pee = preg_replace('|

\s*

|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace + $pee = preg_replace('!

([^<]+)!', "

$1

", $pee); $pee = preg_replace('!

\s*(]*>)\s*

!', "$1", $pee); // don't pee all over a tag $pee = preg_replace("|

(|", "$1", $pee); // problem with nested lists $pee = preg_replace('|

]*)>|i', "

", $pee); @@ -103,20 +119,30 @@ function wpautop($pee, $br = 1) { $pee = preg_replace('!

\s*(]*>)!', "$1", $pee); $pee = preg_replace('!(]*>)\s*

!', "$1", $pee); if ($br) { - $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "", $matches[0]);'), $pee); + $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee); $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks $pee = str_replace('', "\n", $pee); } $pee = preg_replace('!(]*>)\s*
!', "$1", $pee); $pee = preg_replace('!
(\s*]*>)!', '$1', $pee); if (strpos($pee, ')(.*?)!is', 'clean_pre', $pee ); + $pee = preg_replace_callback('!(]*>)(.*?)!is', 'clean_pre', $pee ); $pee = preg_replace( "|\n

$|", '

', $pee ); - //$pee = preg_replace('/

\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone return $pee; } +/** + * Newline preservation help function for wpautop + * + * @since 3.1.0 + * @access private + * @param array $matches preg_replace_callback matches array + * @returns string + */ +function _autop_newline_preservation_helper( $matches ) { + return str_replace("\n", "", $matches[0]); +} function seems_utf8($Str) { # by bmorel at ssi dot fr for ($i=0; $i