Live data from Hacker News

Rainbow.js - code syntax highlighting in 1.2kb

craig.is

11–20 of 34 posts

Re: Rainbow.js - code syntax highlighting in 1.2kb

#11
post #9

Is there a way to style dynamically inserted blocks (say inserted via an ajax call) after the page loads? I did not see an equivalent of the prettify() function of google-code-prettify that lets you do this. Looks great otherwise.

Looks to me like Rainbow.init() would do it.

Yeah I just have to make Rainbow.init() public and make it ignore blocks that have already been processed. Then this will work. Feel free to make a ticket for me on https://github.com/ccampbell/rainbow/issues

Re: Rainbow.js - code syntax highlighting in 1.2kb

#12
post #6

This looks like a very worthy replacement for http://code.google.com/p/google-code-prettify/ I can't see the license specified anywhere, any chance you could add a LICENSE file or similar?

What exactly is it that makes it a worthy replacement? (Yes, I'd like opinions on this; I haven't looked deeply at the guts of the matching algorithms.)

My guess: File size (in a brief check, Rainbow appears to be about half the size, unpacked), active development, and use of github (code-prettify is a few years old, hosted via SVN on Google code, and updated infrequently.)

However, prettify has a much broader range of languages already available for use.

Re: Rainbow.js - code syntax highlighting in 1.2kb

#13
post #5
post #2

Rainbow["onHighlight"] = Rainbow.onHighlight; Isn't that line useless since `obj['property'] == obj.property` is always true? https://github.com/ccampbell/rainbow/blob/master/js/rainbow....

This is because I'm using Google Closure Compiler in advanced mode so all methods that do not get used get renamed. In order to preserve the methods and keep them public you have to reference them like this.

This is what @export (and the related functions in the library for if you are not using annotations) are for. In the context of Closure, this is clumsy. But I expect that not all other minifiers offer the same flexibility.

Re: Rainbow.js - code syntax highlighting in 1.2kb

#16

I would love to see a javascript highliter that consumes TextMate syntax definitions.

That's actually how I started this project! I started working on making a syntax highlighter that could pull in TextMate tmLanguage files, but then I ran into a lot of issues and decided to spin it off into this :)

That is why the syntax in Rainbow is pretty similar.

The main problem had to do with Javascript regex not fully supporting everything that most languages support such as negative/positive lookbehinds and (.*)

Re: Rainbow.js - code syntax highlighting in 1.2kb

#19

Why do people make pages highlighting colorizing things, and then make the subtitle of the page (and other text) be blue on black? This does not inspire confidence.

Purple and orange and green and white on dark blue. My eyes hurt reading this. Pick a couple of colors with relatively high contrast, and make sure the text isn't lighter than the background.
Post reply on HN