summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--system/helpers/text_helper.php30
-rw-r--r--user_guide/changelog.html1
2 files changed, 16 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);
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 39303bdd9..f08c94e87 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -118,6 +118,7 @@ SVN Revision: XXXX</p>
<li>Fixed incorrect parenthesis in form_open() function. (#5135)</li>
<li>Fixed a bug that was ignoring case when comparing controller methods (#4560)</li>
<li>Fixed a bug (#4615) that was not setting SMTP authorization settings when using the initialize function</li>
+ <li>Fixed a bug in highlight_code() in the Text helper that would leave a stray &lt;/span&gt; in certain cases.</li>
</ul>
<h2>Version 1.6.3</h2>