There was a small spike in my referrers stats that led me to a new JavaScript highlighting library — rainbow.js. And since I love bashing other highlighters I couldn't resist this time too :-).

Oh, but be sure that all of this is intended of course as a constructive criticism only!

Size claim

It says upfront that it's 1.2K in size. It isn't. If you include 5 languages it currently supports — it's 8.1K. Which is still impressive given that highlight.js is 11.8K with the same languages.

Features

It doesn't have any beside highlighting itself. No user markup, no line numbers, no language detection, etc. But as far as I understand, it's a design goal. And I can only wish the author a lot of patience in telling people to shut up carefully evaluating feature requests!

Correctness

This is where things get ugly, unfortunately. I loaded up my test suite and on the spot found these:

I'm sure there are many other bugs because…

Speculation

… rainbow.js employs generically defined lexing for all supported languages. Which is good for keeping the library fit and slender but won't work for all the sheer insanity of syntaxes that humanity cared to invent over the latest half a century.

There are backslash escapes and double-quote escapes for strings. PHP, Ruby, Shell all allow embedded code within certain types of strings to a certain extent. JavaScript has literal regexps that clash with division. Pascal has different syntax for hex numbers. Lines starting with # are comments in many languages but in C they're preprocessor directives. And don't even get me started on Perl

All in all I think that current design of rainbow.js won't allow it to grow past a family of not-too-conflicting language syntaxes. Which puts it in the same position as Google Code Prettify. Which for me means that we don't have to worry about this competition yet. But Google should :-).

Anyway I wish the best of luck to Craig Campbell in his endeavor!

Envy

I totally envy their site design!!!

Comments: 3

  1. I figured syntax highlighting is essentially a task of the same complexity as language parsing, if we assume it has to be both good and suitable for many languages. Still, while there is quite a bit of criticism of that library, neither that nor the HackerNews discussion (taken as an example for a discussion by technically-inclined) have mentioned that highlighting syntax using regular expressions is basically impossible in a general case, which I’d consider a major, show-stopping flaw.

  2. Sannis

    Yes, it is worst highlighter site design I'v ever seen. Nyan Cat is much prettier.

    What about http://sunlightjs.com/ review?

  3. Ivan Sagalaev

    Sunlight is still on my list of things to look at.

Add comment