From c0e72b0609827484dc822ded7fcd0a312ed4eb98 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 3 Oct 2008 18:56:06 +0000 Subject: modified how we're performing text highlighting to prevent extra or missing span tags. Namely, removed the start and ending markers, as if the code being highlighted would be styled the same, PHP would put it all in the same , so when we removed our own additions, it would remove the needed opening span style --- system/helpers/text_helper.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'system/helpers/text_helper.php') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 954eb797a..54ef1b580 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -274,27 +274,27 @@ if ( ! function_exists('highlight_code')) array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); // The highlight_string function requires that the text be surrounded - // by PHP tags. Since we don't know if A) the submitted text has PHP tags, - // or B) whether the PHP tags enclose the entire string, we will add our - // own PHP tags around the string along with some markers to make replacement easier later - - $str = ''; - - // All the magic happens here, baby! + // by PHP tags, which we will remove later + $str = ''; // tags + // so we'll replace them with tags. + + if (abs(PHP_VERSION) < 5) { $str = str_replace(array(''), array(''), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + $str = str_replace('<?php ', '', $str); } - - // Remove our artificially added PHP - $str = preg_replace("#\.+?tempstart\
(?:\)?#is", "\n", $str); - $str = preg_replace("#tempend.+#is", "
\n", $str); - + + // Remove our artificially added PHP, and the syntax highlighting that came with it + $str = str_replace('<?php ', '', $str); + $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str); + $str = preg_replace('/<\/span>/i', '', $str); + // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); -- cgit v1.2.3-24-g4f1b