by CodeMonkey
23. October 2009 16:00
I had a small challenge this week as I was wanting to post something where I would include some code. And I had seen on many other webpages how they had syntax highlighting, which I really love when they have, and I wanted something similar. But it's really annoying when you find those few blogs or websites that use a syntax highlighter that, when you try to copy the source, you get the line-numbers aswell as the code.
Enter SyntaxHighligter by Alex Gorbatchev
SyntaxHighligter is a really slick and easy-to-implement JavaScript and Flash-driven syntax-highlighter. It has linenumbers, but includes a feature to open the text from the hightighted area, in a window where the code isn't with line-numbers. You could ask why you need line-numbers in the first place. But I guess the simple answer is, it's alot easier to reference the code if you can point to a specific line instead of having to mark it in some way or form.
Example:
public void MonkeySays()
{
Console.WriteLine("Gimme another banaaana!");
}
All it takes is that you include a heep (or just the ones you know you need (afterall, most of us don't care about every single language, and your readers don't need to download something that is irrelevant) of JavaScript-files, copy some files to your /scripts/ and /styles/ folders, and then you can simply add your code for highlighting like this:
public void MyFirstMethod()
{
}
Now is that easy or what?
And as an added bonus, there are even included some nice themes. Or you could go and theme it yourself!