Web pages contain many snippets from different languages, like HTML, PHP, CSS, and JavaScript. Chili 1.x cannot highlight mixed language source code automatically, but the forthcoming released Chili 2.0 will be is able to do that.

Meanwhile, if you are using a Chili + Enzymes setup, then it’s possible to write an Enzymes template capable of making Chili 1.x highlight a web page perfectly (expanding on my previous php template).

Here is the new updated (2007/02/19) chili-web.php Enzymes template. At the moment it supports XHTML, and embedded CSS, JavaScript, and PHP snippets.

'.htmlentities( $code ).''; } function snippet_php( $open, $code, $close ) { return snippet_wrap( 'html', $open ).snippet_wrap( 'php', $code ).snippet_wrap( 'html', $close ); } function php_inside_html( $matches ) { list( $all, $before, $open, $code, $close ) = $matches; if( '' == $open ) return snippet_wrap( 'html', $all ); else return snippet_wrap( 'html', $before ).snippet_php( $open, $code, $close ); } function php_inside_css( $matches ) { list( $all, $before, $open, $code, $close ) = $matches; if( '' == $open ) return snippet_wrap( 'css', $all ); else return snippet_wrap( 'css', $before ).snippet_php( $open, $code, $close ); } function php_inside_javascript( $matches ) { list( $all, $before, $open, $code, $close ) = $matches; if( '' == $open ) return snippet_wrap( 'javascript', $all ); else return snippet_wrap( 'javascript', $before ).snippet_php( $open, $code, $close ); } function php_inside( $class, $code ) { return preg_replace_callback( '/(?:(.*?)(\<\?php\s)(.*?)(\?\>))|(?:.+)/si', "php_inside_$class", $code ); } function snippet_web( $class, $open, $code, $close ) { return snippet_wrap( 'html', $open ).php_inside( $class, $code ).snippet_wrap( 'html', $close ); } function format_code( $matches ) { list( $all, $before, $open, $tag, $code, $close ) = $matches; if( '' == $open ) { return php_inside( 'html', $all ); } else { switch( $tag ) { case 'script': $class = 'javascript'; break; case 'style' : $class = 'css'; break; default : $class = 'html'; } return php_inside( 'html', $before ).snippet_web( $class, $open, $code, $close ); } } function format_clean( $out ) { do { $len = strlen( $out ); $out = preg_replace( '/(\[^<]*)\<\/code\>\/is', '$1', $out ); } while( $len != strlen( $out ) ); return $out; } } ?>

)(.*?)(\<\/\3\>))|(?:.+)/is', 'format_code', $this->result );
	echo format_clean( $out );
?>

The WordPress file /wp-content /themes /default /comments-popup.php is a page that uses all the supported languages, so it’s a good test for the previous template:

<?php echo get_option('blogname'); ?> - Comments on <?php the_title(); ?>

Comments

RSS feed for comments on this post.

ping_status) { ?>

The URL to TrackBack this entry is:

post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie echo(get_the_password_form()); } else { ?>
  1. by — @

No comments yet.

comment_status) { ?>

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed:

" />


ID); ?>

Sorry, the comment form is closed at this time.

Powered by WordPress

Chili & Enzymes confirm to be a perfect match.