2009/4/2 Justin Martin <frozenf...@thefrozenfire.com>:
> Hello everyone,
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Just as an update, I reviewed my previous patch and re did it (attached).

Instead of adding the highlight.class_* INI entries, this simply adds two:

* highlight.inline_styles (default 1), set to 0 to trigger the use of classes
* highlight.class_prefix (default ""), set to a class prefix of choice
to prevent naming conflicts

I thought adding a class_prefix would be better than adding a yet
another class name on the <code> tag, prefixing should work out just
perfect.


-- 
Kalle Sommer Nielsen
ka...@php.net
Index: ZendEngine2/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
--- ZendEngine2/zend_highlight.c        31 Dec 2008 11:15:32 -0000      
1.49.2.3.2.2.2.6
+++ ZendEngine2/zend_highlight.c        2 Apr 2009 17:59:48 -0000
@@ -86,37 +86,47 @@
 #endif /* ZEND_MULTIBYTE */
 }
 
-
 ZEND_API void zend_highlight(zend_syntax_highlighter_ini 
*syntax_highlighter_ini TSRMLS_DC)
 {
        zval token;
        int token_type;
+       zend_bool inline_styles = syntax_highlighter_ini->inline_style;
+       char *class_prefix = syntax_highlighter_ini->class_prefix;
        char *last_color = syntax_highlighter_ini->highlight_html;
+       char *class = "html";
        char *next_color;
 
        zend_printf("<code>");
-       zend_printf("<span style=\"color: %s\">\n", last_color);
+
+       if (inline_styles) {
+               zend_printf("<span style=\"color: %s\">\n", last_color);
+       } else {
+               zend_printf("<span class=\"%s%s\">", class_prefix, class);
+       }
+
        /* highlight stuff coming back from zendlex() */
        token.type = 0;
        while ((token_type=lex_scan(&token TSRMLS_CC))) {
                switch (token_type) {
                        case T_INLINE_HTML:
+                               class = "html";
                                next_color = 
syntax_highlighter_ini->highlight_html;
                                break;
                        case T_COMMENT:
                        case T_DOC_COMMENT:
+                               class = "comment";
                                next_color = 
syntax_highlighter_ini->highlight_comment;
                                break;
                        case T_OPEN_TAG:
                        case T_OPEN_TAG_WITH_ECHO:
-                               next_color = 
syntax_highlighter_ini->highlight_default;
-                               break;
                        case T_CLOSE_TAG:
+                               class = "default";
                                next_color = 
syntax_highlighter_ini->highlight_default;
                                break;
                        case '"':
                        case T_ENCAPSED_AND_WHITESPACE:
                        case T_CONSTANT_ENCAPSED_STRING:
+                               class = "string";
                                next_color = 
syntax_highlighter_ini->highlight_string;
                                break;
                        case T_WHITESPACE:
@@ -125,7 +135,9 @@
                                continue;
                                break;
                        default:
+                               class = "default";
                                if (token.type == 0) {
+                                       class = "keyword";
                                        next_color = 
syntax_highlighter_ini->highlight_keyword;
                                } else {
                                        next_color = 
syntax_highlighter_ini->highlight_default;
@@ -139,7 +151,11 @@
                        }
                        last_color = next_color;
                        if (last_color != 
syntax_highlighter_ini->highlight_html) {
-                               zend_printf("<span style=\"color: %s\">", 
last_color);
+                               if (inline_styles) {
+                                       zend_printf("<span style=\"color: 
%s\">", last_color);
+                               } else {
+                                       zend_printf("<span class=\"%s%s\">", 
class_prefix, class);
+                               }
                        }
                }
                switch (token_type) {
@@ -177,7 +193,11 @@
                                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);
+                               if (inline_styles) {
+                                       zend_printf("<span style=\"color: 
%s\">", syntax_highlighter_ini->highlight_comment);
+                               } else {
+                                       zend_printf("<span 
class=\"%scomment\">", class_prefix);
+                               }
                        }
                }
                zend_html_puts(LANG_SCNG(yy_text), (LANG_SCNG(yy_limit) - 
LANG_SCNG(yy_text)) TSRMLS_CC);
Index: ZendEngine2/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
--- ZendEngine2/zend_highlight.h        31 Dec 2008 11:15:32 -0000      
1.25.2.1.2.1.2.2
+++ ZendEngine2/zend_highlight.h        2 Apr 2009 17:59:58 -0000
@@ -36,6 +36,8 @@
        char *highlight_default;
        char *highlight_string;
        char *highlight_keyword;
+       zend_bool inline_styles;
+       char *class_prefix;
 } zend_syntax_highlighter_ini;
 
 
Index: ext/standard/basic_functions.c
===================================================================
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.725.2.31.2.64.2.87
diff -u -r1.725.2.31.2.64.2.87 basic_functions.c
--- ext/standard/basic_functions.c      27 Mar 2009 02:32:56 -0000      
1.725.2.31.2.64.2.87
+++ ext/standard/basic_functions.c      2 Apr 2009 17:59:21 -0000
@@ -5090,6 +5090,8 @@
        syntax_highlighter_ini->highlight_html    = INI_STR("highlight.html");
        syntax_highlighter_ini->highlight_keyword = 
INI_STR("highlight.keyword");
        syntax_highlighter_ini->highlight_string  = INI_STR("highlight.string");
+       syntax_highlighter_ini->inline_styles     = 
INI_BOOL("highlight.inline_styles");
+       syntax_highlighter_ini->class_prefix      = 
INI_STR("highlight.class_prefix");
 }
 /* }}} */
 
Index: main/main.c
===================================================================
RCS file: /repository/php-src/main/main.c,v
retrieving revision 1.640.2.23.2.57.2.47
diff -u -r1.640.2.23.2.57.2.47 main.c
--- main/main.c 27 Mar 2009 02:34:06 -0000      1.640.2.23.2.57.2.47
+++ main/main.c 2 Apr 2009 17:57:59 -0000
@@ -394,13 +394,15 @@
 /* {{{ PHP_INI
  */
 PHP_INI_BEGIN()
-       PHP_INI_ENTRY_EX("define_syslog_variables",     "0",                    
        PHP_INI_ALL,    NULL,                   php_ini_boolean_displayer_cb)
-       PHP_INI_ENTRY_EX("highlight.bg",                        HL_BG_COLOR,    
        PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
+       PHP_INI_ENTRY_EX("define_syslog_variables",     "0",                    
PHP_INI_ALL,    NULL,                   php_ini_boolean_displayer_cb)
+       PHP_INI_ENTRY_EX("highlight.bg",                HL_BG_COLOR,            
PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
        PHP_INI_ENTRY_EX("highlight.comment",           HL_COMMENT_COLOR,       
PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
        PHP_INI_ENTRY_EX("highlight.default",           HL_DEFAULT_COLOR,       
PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
-       PHP_INI_ENTRY_EX("highlight.html",                      HL_HTML_COLOR,  
        PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
+       PHP_INI_ENTRY_EX("highlight.html",              HL_HTML_COLOR,          
PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
        PHP_INI_ENTRY_EX("highlight.keyword",           HL_KEYWORD_COLOR,       
PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
        PHP_INI_ENTRY_EX("highlight.string",            HL_STRING_COLOR,        
PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
+       PHP_INI_ENTRY_EX("highlight.inline_styles",     "1",                    
PHP_INI_ALL,    NULL,                   php_ini_boolean_displayer_cb)
+       PHP_INI_ENTRY("highlight.class_prefix",         "",                     
PHP_INI_ALL,    NULL)
 
        STD_PHP_INI_BOOLEAN("allow_call_time_pass_reference",   "1",    
PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateBool,   
allow_call_time_pass_reference, zend_compiler_globals,  compiler_globals)
        STD_PHP_INI_BOOLEAN("asp_tags",                         "0",            
PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateBool,                   
asp_tags,                               zend_compiler_globals,  
compiler_globals)

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

Reply via email to