Update: I no longer (2012-08-05) use Chili; I've switched to Prism.
I like the idea of syntax coloring, so let's see if Chili works:
alert('Hello, world');
and another: <div>Hello, <em>world</em></div>
I'm trying to be as HTML5-compliant as possible, at least in the sense of using their standards rather than making up my own, so the Chili setup I'm using is:
$.extend(ChiliBook, {
automatic: false,
codeLanguage: function(el){
// use the HTML5 language class
var recipeName = /language-(\S+)/.exec(el.className);
return recipeName ? recipeName[1] : '';
}
});
$(function(){
$('code[class*=language-]').not($('pre code')).chili({lineNumbers: false})
.otherwise().chili({lineNumbers: true});
});
Sweet! The idea of the above code is to look for a class that starts with "language-" and use that as the recipe for Chili (rather than Chili's built-in way of taking the entire className). It also assumes that any code in a pre
element should have line numbers, and anything else should not. It uses the cute and brilliant otherwise
plugin from
http://groups.google.com/group/jquery-en/browse_thread/thread/6be2a127822a108d.
Update: It looks like line numbering works only intermittently. Oh well; I won't fix it.
Andrea says:
Could you please tell when line numbering doesn’t work?
August 29, 2008, 5:27 pmI’ll be glad to fix it.