summaryrefslogtreecommitdiffstats
path: root/system/helpers/text_helper.php
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-10-03 20:56:06 +0200
committerDerek Jones <derek.jones@ellislab.com>2008-10-03 20:56:06 +0200
commitc0e72b0609827484dc822ded7fcd0a312ed4eb98 (patch)
tree99131a19ef37e99727bb70d9605a06d14dc59a20 /system/helpers/text_helper.php
parent26bde91ef36cacd22772102d3083277bd937a60d (diff)
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 <span>, so when we removed our own additions, it would remove the needed opening span style
Diffstat (limited to 'system/helpers/text_helper.php')
-rw-r--r--system/helpers/text_helper.php30
1 files changed, 15 insertions, 15 deletions
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 = '<?php tempstart'."\n".$str.'tempend ?>';
-
- // All the magic happens here, baby!
+ // by PHP tags, which we will remove later
+ $str = '<?php '.$str.' ?>'; // <?
+
+ // All the magic happens here, baby!
$str = highlight_string($str, TRUE);
- // Prior to PHP 5, the highlight function used icky font tags
- // so we'll replace them with span tags.
- if (abs(phpversion()) < 5)
+ // Prior to PHP 5, the highligh function used icky <font> tags
+ // so we'll replace them with <span> tags.
+
+ if (abs(PHP_VERSION) < 5)
{
$str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str);
$str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
+ $str = str_replace('<span style="color: #0000BB">&lt;?php ', '<span style="color: #0000BB">', $str);
}
-
- // Remove our artificially added PHP
- $str = preg_replace("#\<code\>.+?tempstart\<br />(?:\</span\>)?#is", "<code>\n", $str);
- $str = preg_replace("#tempend.+#is", "</span>\n</code>", $str);
-
+
+ // Remove our artificially added PHP, and the syntax highlighting that came with it
+ $str = str_replace('<span style="color: #0000BB">&lt;?php&nbsp;', '<span style="color: #0000BB">', $str);
+ $str = preg_replace('/(<span style="color: #0000BB">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is', "$1</span>\n</span>\n</code>", $str);
+ $str = preg_replace('/<span style="color: #[A-Z0-9]+"\><\/span>/i', '', $str);
+
// Replace our markers back to PHP tags.
$str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $str);