Hello everyone,

I'd like to propose a very small update, which would have no
backwards-compatibility problems, and would bring PHP closer to
standards compliance.

The update I'd like to propose is to the Zend Highlighter for PHP,
specifically related to the highlight_file and highlight_string
functions, as well as the php -s command.

My proposal is a very simple one, which would add a third parameter,
which would be optional, which would select between "inline" styling,
and external styling. The proposed syntax for highlight_file would be:

mixed highlight_file (string $filename [, bool $return= false [, bool
$inline= true]]);

Currently, syntax highlighting is done inline, by means of the style
attribute of the span tag (<span style="color: #FFFFFF">...</span>). My
proposition would be for a "class" attribute to be set instead of the
style attribute, based on the value of $inline (<span
class="phpcomment">...</span>).

The issue this modification is intended to fix is that many developers
who intend to provide syntax highlighting in their project end up
rolling their own code for such. By providing external styling code
rather than inline styling, it makes it possible to modify the style of
all highlighted code, without modifying the code itself. It also
provides the capability to extend the viewing experience with
Javascript, such as code folding functionality.

I've taken the liberty to produce a very quick and dirty patch, which is
by no means complete, but provides a cursory example of what I intend.

I'd like to clarify that this is the first time I've modified PHP's
code, and I know very little C. The only modifications I've done for PHP
in the past have been in the PHP-GTK branch, attempting to fix the
documentation generator to work with the non-standard extension
structure. If I've submitted my proposal poorly, I apologize.

Please offer any comments you have.

Thank you,
Justin Martin aka FrozenFire
Index: Zend/zend_highlight.c
===================================================================
RCS file: /repository/ZendEngine2/zend_highlight.c,v
retrieving revision 1.49.2.3.2.2.2.6
diff -u -r1.49.2.3.2.2.2.6 zend_highlight.c
--- Zend/zend_highlight.c	31 Dec 2008 11:15:32 -0000	1.49.2.3.2.2.2.6
+++ Zend/zend_highlight.c	2 Apr 2009 03:33:35 -0000
@@ -95,7 +95,7 @@
 	char *next_color;
 
 	zend_printf("<code>");
-	zend_printf("<span style=\"color: %s\">\n", last_color);
+	zend_printf("<span class=\"%s\">\n", last_color);
 	/* highlight stuff coming back from zendlex() */
 	token.type = 0;
 	while ((token_type=lex_scan(&token TSRMLS_CC))) {
@@ -139,7 +139,7 @@
 			}
 			last_color = next_color;
 			if (last_color != syntax_highlighter_ini->highlight_html) {
-				zend_printf("<span style=\"color: %s\">", last_color);
+				zend_printf("<span class=\"%s\">", last_color);
 			}
 		}
 		switch (token_type) {
@@ -177,7 +177,7 @@
 				zend_printf("</span>");
 			}
 			if (syntax_highlighter_ini->highlight_comment != syntax_highlighter_ini->highlight_html) {
-				zend_printf("<span style=\"color: %s\">", syntax_highlighter_ini->highlight_comment);
+				zend_printf("<span class=\"%s\">", syntax_highlighter_ini->highlight_comment);
 			}
 		}
 		zend_html_puts(LANG_SCNG(yy_text), (LANG_SCNG(yy_limit) - LANG_SCNG(yy_text)) TSRMLS_CC);
Index: Zend/zend_highlight.h
===================================================================
RCS file: /repository/ZendEngine2/zend_highlight.h,v
retrieving revision 1.25.2.1.2.1.2.2
diff -u -r1.25.2.1.2.1.2.2 zend_highlight.h
--- Zend/zend_highlight.h	31 Dec 2008 11:15:32 -0000	1.25.2.1.2.1.2.2
+++ Zend/zend_highlight.h	2 Apr 2009 03:33:35 -0000
@@ -22,12 +22,12 @@
 #ifndef ZEND_HIGHLIGHT_H
 #define ZEND_HIGHLIGHT_H
 
-#define HL_COMMENT_COLOR     "#FF8000"    /* orange */
-#define HL_DEFAULT_COLOR     "#0000BB"    /* blue */
-#define HL_HTML_COLOR        "#000000"    /* black */
-#define HL_STRING_COLOR      "#DD0000"    /* red */
-#define HL_BG_COLOR          "#FFFFFF"    /* white */
-#define HL_KEYWORD_COLOR     "#007700"    /* green */
+#define HL_COMMENT_COLOR     "phpcomment"
+#define HL_DEFAULT_COLOR     "phpdefault"
+#define HL_HTML_COLOR        "phphtml"
+#define HL_STRING_COLOR      "phpstring"
+#define HL_BG_COLOR          "phpbackground"
+#define HL_KEYWORD_COLOR     "phpkeyword"
 
 
 typedef struct _zend_syntax_highlighter_ini {

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to