Skip to content

Commit d766dd3

Browse files
committed
Drop support for < 5.3 from highlight_php()
...to use HTML5
1 parent d5c8c1d commit d766dd3

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

include/layout.inc

+6-13
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,19 @@ ini_set('highlight.html', 'html');
1414
// Highlight PHP code
1515
function highlight_php($code, $return = FALSE)
1616
{
17-
// Using OB, as highlight_string() only supports
18-
// returning the result from 4.2.0
19-
ob_start();
20-
highlight_string($code);
21-
$highlighted = ob_get_contents();
22-
ob_end_clean();
17+
$highlighted = highlight_string($code, TRUE);
2318

24-
// This should eventually be a php_syntax_check() call when we move to PHP5
25-
// But use this ugly hack for now to avoid code snippets with bad syntax screwing up the highlighter
26-
if(strstr($highlighted,"include/layout.inc</b>")) $highlighted = '<span class="html">'.nl2br(htmlentities($code))."</span>";
19+
// Use this ugly hack for now to avoid code snippets with bad syntax screwing up the highlighter
20+
if(strstr($highlighted, "include/layout.inc</b>")) {
21+
$highlighted = '<span class="html">'. nl2br(htmlentities($code, ENT_HTML5), FALSE) ."</span>";
22+
}
2723

2824
// Fix output to use CSS classes and wrap well
2925
$highlighted = '<div class="phpcode">' . str_replace(
3026
array(
3127
'&nbsp;',
3228
'<br>',
33-
'<font color="', // for PHP 4
34-
'<span style="color: ', // from PHP 5.0.0RC1
29+
'<span style="color: ',
3530
'</font>',
3631
"\n ",
3732
' ',
@@ -41,7 +36,6 @@ function highlight_php($code, $return = FALSE)
4136
' ',
4237
"<br>\n",
4338
'<span class="',
44-
'<span class="',
4539
'</span>',
4640
"\n&nbsp;",
4741
'&nbsp; ',
@@ -62,7 +56,6 @@ function commonHeader($title) { site_header($title); }
6256
function commonFooter() { site_footer(); }
6357

6458
// Resize the image using the output of make_image()
65-
// (considering possible HTML/XHTML image tag endings)
6659
function resize_image($img, $width = 1, $height = 1)
6760
{
6861
// Drop width and height values from image if available

0 commit comments

Comments
 (0)