- Make the auto-linebreak filter also ignore the contents of <script>.

This makes it easier to use JavaScript (e.g. Google Adsense) inside blocks.
4.7.x
Steven Wittens 2005-04-20 02:55:20 +00:00
parent 05e9c8c76c
commit 755da4bc0e
2 changed files with 44 additions and 12 deletions

View File

@ -942,18 +942,34 @@ function _filter_html($text, $format) {
* Based on: http://photomatt.net/scripts/autop
*/
function _filter_autop($text) {
// Split at <pre> and </pre> tags
$chunks = preg_split('@(</?pre[^>]*>)@', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
// Split at <pre>, <script> and </pre>, </script> 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 <pre> ignored <script> ignored </script> ignored </pre> processed"
$chunks = preg_split('@(</?(?:pre|script)[^>]*>)@', $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('|<br />\s*<br />|', "\n\n", $chunk);
$chunk = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $chunk); // Space things out a little

View File

@ -942,18 +942,34 @@ function _filter_html($text, $format) {
* Based on: http://photomatt.net/scripts/autop
*/
function _filter_autop($text) {
// Split at <pre> and </pre> tags
$chunks = preg_split('@(</?pre[^>]*>)@', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
// Split at <pre>, <script> and </pre>, </script> 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 <pre> ignored <script> ignored </script> ignored </pre> processed"
$chunks = preg_split('@(</?(?:pre|script)[^>]*>)@', $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('|<br />\s*<br />|', "\n\n", $chunk);
$chunk = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $chunk); // Space things out a little