How to Highlight Mixed Language Source Code

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.

{[.chili-web /enzymes/chili-web.php]}

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:

{[.test /enzymes/chili-web.php]}

Chili & Enzymes confirm to be a perfect match.

An enzyme for transcluding a web page

2018-06-14: This post was very different when I first published it, many years ago. Time goes by, and IFRAME is no longer that good an option when websites can specify new headers like X-Frame-Options. Meanwhile, I also had to deactivate my Enzymes plugin and only keep my newer Nzymes plugin active. Confronted with the alternative to leave this here as a useless contribution to mankind, I opted for changing the examples while keeping their original spirit instead.

Enzymes Nzymes can be complex PHP scripts, but basic enzymes are also very useful. These allow to transclude some web content into a post. Enzymes Nzymes makes it easy to do it over and over, without having to remember: “how did I do it?”

This is got by the statement {[.show-image()]}:

This is got by the statement {[.show-quote()]}:

show-image:

return "<img src='https://picsum.photos/200/300/?random' />";

show-quote:

$response = file_get_contents('https://random-quote-generator.herokuapp.com/api/quotes/random');
$decoded = json_decode($response, TRUE);
$quote = htmlspecialchars($decoded['quote']);
$author = htmlspecialchars($decoded['author']);
return "<span>$quote (by $author)</span>";

Easy, isn’t it?