Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43583 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60748 invoked from network); 2 Apr 2009 03:47:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Apr 2009 03:47:22 -0000 X-Host-Fingerprint: 66.183.89.177 unknown Received: from [66.183.89.177] ([66.183.89.177:27565] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/F0-47115-84534D94 for ; Wed, 01 Apr 2009 22:47:22 -0500 Message-ID: <6F.F0.47115.84534D94@pb1.pair.com> To: internals@lists.php.net Date: Wed, 01 Apr 2009 20:47:17 -0700 User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080708040904060709090202" X-Posted-By: 66.183.89.177 Subject: Update to Zend Highlighter From: frozenfire@thefrozenfire.com (Justin Martin) --------------080708040904060709090202 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 (...). My proposition would be for a "class" attribute to be set instead of the style attribute, based on the value of $inline (...). 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 --------------080708040904060709090202 Content-Type: text/x-patch; name="phphighlightpatch.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="phphighlightpatch.diff" 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(""); - zend_printf("\n", last_color); + zend_printf("\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("", last_color); + zend_printf("", last_color); } } switch (token_type) { @@ -177,7 +177,7 @@ zend_printf(""); } if (syntax_highlighter_ini->highlight_comment != syntax_highlighter_ini->highlight_html) { - zend_printf("", syntax_highlighter_ini->highlight_comment); + zend_printf("", 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 { --------------080708040904060709090202--