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:
- prefixed strings in Python (
r""
,u""
) aren't detected - tripple-quote strings in Python are detected wrong (first two quotes are treated as strings)
- backslash escapes in strings aren't detected which can break the whole further highlighting in cases like
"a \" b"
- names of old-style Python classes are not recognized (because of the lack of parens after the names)
- doctype declaration in HTML is treated as a tag
- tag attributes in HTML aren't detected reliably, like "checked" here:
<input checked type="checkbox">
- in the CSS snippet
{margin: 1cm 2cm 1.3cm 4cm;}
"1." and "4cm" are not recognized as values - in
div {width: 100%}
"100%" is not recognized as a value - in the selector
p[lang=en]
all "p", "lang" and "en" are detected as tags - in JavaScript literal regexps are not distinguished from devision operators which leads to all sorts of breakage
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
Yes, it is worst highlighter site design I'v ever seen. Nyan Cat is much prettier.
What about http://sunlightjs.com/ review?
Sunlight is still on my list of things to look at.