From 755da4bc0e52b8f2ce8a2a470974b6a4a322bc53 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Wed, 20 Apr 2005 02:55:20 +0000 Subject: [PATCH] - Make the auto-linebreak filter also ignore the contents of tags. + // We don't apply any processing to the contents of these tags to avoid messing + // up code. We look for matched pairs and allow basic nesting. For example: + // "processed
 ignored  ignored 
processed" + $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; + $ignore = false; + $ignoretag = ''; $output = ''; foreach ($chunks as $i => $chunk) { if ($i % 2) { - // Opening or closing pre tag? - $pre = ($chunk{1} != '/'); + // Opening or closing tag? + $open = ($chunk{1} != '/'); + list(, $tag) = split('[< ]', $chunk); + if (!$ignore) { + if ($open) { + $ignore = true; + $ignoretag = $tag; + } + } + // Only allow a matching tag to close it. + else if (!$open && $ignoretag == $tag) { + $ignore = false; + $ignoretag = ''; + } } - else if (!$pre) { + else if (!$ignore) { $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 diff --git a/modules/filter/filter.module b/modules/filter/filter.module index dd142ca2405..c77c51351e9 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -942,18 +942,34 @@ function _filter_html($text, $format) { * Based on: http://photomatt.net/scripts/autop */ function _filter_autop($text) { - // Split at
 and 
tags - $chunks = preg_split('@(]*>)@', $text, -1, PREG_SPLIT_DELIM_CAPTURE); + // Split at
,  tags.
+  // We don't apply any processing to the contents of these tags to avoid messing
+  // up code. We look for matched pairs and allow basic nesting. For example:
+  // "processed 
 ignored  ignored 
processed" + $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; + $ignore = false; + $ignoretag = ''; $output = ''; foreach ($chunks as $i => $chunk) { if ($i % 2) { - // Opening or closing pre tag? - $pre = ($chunk{1} != '/'); + // Opening or closing tag? + $open = ($chunk{1} != '/'); + list(, $tag) = split('[< ]', $chunk); + if (!$ignore) { + if ($open) { + $ignore = true; + $ignoretag = $tag; + } + } + // Only allow a matching tag to close it. + else if (!$open && $ignoretag == $tag) { + $ignore = false; + $ignoretag = ''; + } } - else if (!$pre) { + else if (!$ignore) { $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