Wednesday, 1 August 2007

SyntaxHighlighting for Code

I found a nice syntax highlighting javascipt/CSS library. It's called SyntaxHighlighter by Alex Gorbatchev. Here's an example of highlighting java code:
public interface EqualityHelper {
    
    public EqualityHelper forObject(Object baseObject);
    
    public boolean isEqual(Object other);
    
    public int getHash();

}
It supports syntax coloring with different dialects. It looks very straightforward to create your own as well. Here's one that highlights XML, to show the code that created the above. In order to make this work, you've got to get some CSS and javascript entries into your HTML. There a javascript file for each "brush" which highlights a kind of code. In Blojsom, I added these via it's template management capabilities to the head and footer templates. Here's the relevent ones I've used on this page:

Technorati Tags:

Posted by spout at 8:34 PM in the internet, web, web 2.0 and beyond
« August »
SunMonTueWedThuFriSat
   1234
567891011
12131415161718
19202122232425
262728293031