Changes
- Added support for local line numbers
- plain
- starting from an offset
- automatically segmented
- Improved the PHP recipe for defaulting to PHP instead of HTML when no <? is found
Andrea Ercolino, Software Engineer
Chili 2.0 supports a new recipe format which is a bit more structured than the old one and will make hard-to-highlight languages a thing of the past. BTW, old recipes won’t be accepted by Chili 2.0. (although a simple manual conversion is possible)
First of all let’s see an example of how to convert a recipe in the old format to the new one.
What follows is a piece of recipe (for JavaScript) in the old format
{[ .js-old | .hilite( =javascript= ) ]}
And here is the same piece in the new format
{[ .js-new | .hilite( =javascript= ) ]}
As you see, they are very similar. Here are all the differences:
_style makes a big difference with respect to the past: CSS styles can now be embedded into the recipe. Separate stylesheets are no longer supported by the autoloading engine, but you can load them by yourself, if you prefer to keep them apart.
Another important difference about CSS is that now Chili builds the class associated to a step, by prefixing the _name to the step name, separated by __ (a double underscore). So, for example, the class for the multiline comment will be js__ml_comment.
Besides the minor changes described in the previous section, the new format is much more powerful thanks to the major improvement I’m going to describe here.
The old recipe format supported an optional replacement property of a step, by means of which you could customize how the highlighting was applied to the matched text. Such a feature was useful when you captured subexpressions and wanted to highlight them separately.
Now _replace replaces replacement (sic) and it’s still optional.
As before, if you don’t specify a _replace property, Chili will default to <span class=”$0″>$$</span>, where $0 and $$ refer to the name of the current step and the matched text respectively.
As before, _replace can also be a different string expression, like in the following step, extracted from the MySQL recipe
{[ .replace-string | .hilite( =javascript= ) ]}
What to note in the above example:
In Chili 2.0, _replace can also be a function, like in the following step, extracted from the new HTML recipe
{[ .replace-function | .hilite( =javascript= ) ]}
What to note in the above example:
A Chili 2.0 recipe contains blocks (like _main), which contain steps (like tag_start). An expression can be built for referencing each module, be it a recipe, a block, or a step. For example, /tag_attrs is the tag_attrs block in the current recipe.
The JavaScript code inside a _replace function can use the x method of this.
x takes two arguments: a subject to process, and an optional module to use.
x returns the subject escaped for HTML if no module is given, or the module is not available, else it returns the result of applying the module to the subject using Chili 2.0.
If the ChiliBook option recipeLoading is true, any unavailable module will be automatically loaded.
As an example, here is the new HTML recipe
{[ .html-new | .hilite( =javascript= ) ]}
What to note in the above example:
A module path is an expression that identifies a Chili 2.0 module. A path has three components (though some can be hidden) separated by a / (forward slash), each with a specific meaning: recipe / block / step. (white space added for clarity)
Here is a list of all the combinations in a module path:
As you see, leading slashes have a meaning.
I think that Chili 2.0 is pretty good at highlighting, but it needs more fine recipes to succeed. For this release I’ve rewritten some from scratch, and converted some others. I’m not a good programmer in languages other than the ones for which I rewrote a recipe. But if you are and have time and will, then you could write a Chili 2.0 recipe for your favorite language, together with a couple of working samples, and send all to me. I’d be very happy to add your contributed recipes to the project as soon as they are available.
Here is the start page for Chili 2.0 where you’ll find setup instructions and some examples.