cvs diff -u filter.module (in directory C:\CVS\drupal\modules) Index: filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter.module,v retrieving revision 1.53 diff -u -r1.53 filter.module --- filter.module 3 Mar 2005 20:51:27 -0000 1.53 +++ filter.module 7 Mar 2005 13:37:16 -0000 @@ -942,27 +942,41 @@ /** * Convert line breaks into

and
in an intelligent fashion. - * From: http://photomatt.net/scripts/autop + * Based on: http://photomatt.net/scripts/autop */ function _filter_autop($text) { - $text = preg_replace('|\n*$|', '', $text) ."\n\n"; // just to make things a little easier, pad the end - $text = preg_replace('|
\s*
|', "\n\n", $text); - $text = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $text); // Space things out a little - $text = preg_replace('!()!', "$1\n", $text); // Space things out a little - $text = preg_replace("/\n\n+/", "\n\n", $text); // take care of duplicates - $text = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "

$1

\n", $text); // make paragraphs, including one at the end - $text = preg_replace('|

\s*?

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

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

]*)>|i', "

", $text); - $text = str_replace('

', '

', $text); - $text = preg_replace('!

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

!', "$1", $text); - $text = preg_replace('|(?)\s*\n|', "
\n", $text); // make line breaks - $text = preg_replace('!(]*>)\s*
!', "$1", $text); - $text = preg_replace('!
(\s*)!', '$1', $text); - $text = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $text); - - return $text; + // Split at
 and 
tags + $chunks = preg_split('@(]*>)@', $text, -1, PREG_SPLIT_DELIM_CAPTURE); + // Note: PHP ensures the array consists of alternating delimiters and literals + // and begins and ends with a literal (inserting NULL as required). + $pre = false; + $output = ''; + foreach ($chunks as $i => $chunk) { + if ($i % 2) { + // Opening or closing pre tag? + $pre = ($chunk{1} != '/'); + } + else if (!$pre) { + $chunk = preg_replace('|\n*$|', '', $chunk) ."\n\n"; // just to make things a little easier, pad the end + $chunk = preg_replace('|
\s*
|', "\n\n", $chunk); + $chunk = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $chunk); // Space things out a little + $chunk = preg_replace('!()!', "$1\n", $chunk); // Space things out a little + $chunk = preg_replace("/\n\n+/", "\n\n", $chunk); // take care of duplicates + $chunk = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "

$1

\n", $chunk); // make paragraphs, including one at the end + $chunk = preg_replace('|

\s*?

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

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

]*)>|i', "

", $chunk); + $chunk = str_replace('

', '

', $chunk); + $chunk = preg_replace('!

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

!', "$1", $chunk); + $chunk = preg_replace('|(?)\s*\n|', "
\n", $chunk); // make line breaks + $chunk = preg_replace('!(]*>)\s*
!', "$1", $chunk); + $chunk = preg_replace('!
(\s*)!', '$1', $chunk); + $chunk = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $chunk); + } + $output .= $chunk; + } + return $output; }