Beautify your blog’s code samples with these syntax highlighters
Previous attempts to post more than just CSS or XHTML code samples on d’bug have been met with what I would consider unsatisfactory results. So I started researching syntax highlighters in preparation for those articles where I need to delve a little deeper into a language. This short list I came up with is, well, very short. To be honest, most syntax highlighters are poorly executed, poorly performing, and the intended use is not always as clear as it might seem.
My criteria for choosing these was fairly elementary. Each code syntax highlighter should have basic email support, a simple set of installation procedures and a few release notes. My DreamHost hosting account needs to be able to support it as well. That rules out anything written in .NET or Java. Finally, these need to be plug-n-play, and should not allow inline editing. Numerous highlighters require you to copy-and-paste code on a third-party site, or are executed within a textarea for rich text editing.
If you have other suggestions, please share them in the comments.
GeSHi

Overview:
GeSHi is by far the most recognizable code syntax highlighter currently available. Many of the WordPress plugins that I encountered were simply built on top of GeSHi, and the number of supported languages is well beyond what most bloggers would need.
Requirements:
PHP
Supported Languages:
Actionscript, ADA, Apache Log, AppleScript, ASM, ASP, AutoIT, Backus-Naur form, Bash, BlitzBasic, C, C for Macs, C#, C++, CAD DCL, CadLisp, CFDG, ColdFusion, CSS, Delphi, DIV, DOS, Eiffel, Fortran, FreeBasic, GML, Groovy, HTML, Inno, IO, Java, Java 5, Javascript, LaTeX, Lisp, Lua, Microprocessor ASM, mIRC, MySQL, NSIS, Objective C, OCaml, OpenOffice BASIC, Oracle 8 SQL, Pascal, Perl, PHP, PL/SQL, Python, Q(uick)BASIC, robots.txt, Ruby, SAS, Scheme, SDLBasic, Smalltalk, Smarty, SQL, T-SQL, TCL, thinBasic, Uno IDL, VB.NET, Visual BASIC, Visual Fox Pro, Winbatch, X++, XML, Z80 ASM
Syntax Highlighter
http://code.google.com/p/syntaxhighlighter/

Overview:
Next in line behind GeSHi would be Syntax Highlighter, which is hosted by Google Code. The author boasts that no server-side language or experience is necessary to use the plugin, since it is written 100% in JavaScript. Unfortunately, he goes on to point out that performance dwindles considerably when the size of the code snippet increases beyond a few kilobytes.
Requirements:
JavaScript
Supported Languages:
C++, C#, CSS, Delphi, Java, JavaScript, PHP, Python, Ruby, Sql, VB, XML/HTML
ColourCode
http://22bits.exofire.net/browse/code/colourcode

Overview:
I was pleasantly surprised when I stumbled across ColourCode. It has received little acclaim, probably due to the fact that it requires Ruby, and not PHP. However, the rendering performance is surprisingly fast in the examples that the author illustrates real-time. According to the Web site the current stable version will be the last for awhile.
Requirements:
Ruby
Supported Languages:
Javascript, Java, C++, C#, Python, ShellScript, Ruby, PHP, HTML
Chili & Enzymes

Overview:
Of those listed here, Chili was the only one that I did try, albeit in the distant past with a previous release. It worked well enough in the performance category, but I did experience some cross-browser issues. I do not doubt that those have been dealt with, and there is sufficient support for this as a WordPress plugin that any further issues could easily be fixed.
Requirements:
PHP and jQuery
Supported Languages:
C++, C#, CSS, Delphi, Java, JavaScript, LotusScript, MySQL, PHP, XHTML
Leave a Comment
Comments are moderated. No profanity. Only <a>...</a>, <blockquote>...</blockquote>, and <code>...</code> are allowed.
Seperate paragraphs by pressing the "Enter" key twice, or press it once to break to a new line.
13 Comments
#01, Sep 06 2007
Jos Hirth
I also evaluated different highlighters for my blog a while ago. I used GeSHi in the past, but I didn’t feel like writing a filter for that again.
I also tried Syntax Highlighter, but the performance was downright terrible. It often didn’t even manage to highlight more than 50 lines of code.
At the end I went with SHJS (sf.net). It’s also client sided, but it’s very fast and compact. It even highlights thousands of lines on a 500mhz machine without any issues. Compatibility is also very good.
#02, Sep 06 2007
Alex Miller
I use SyntaxHighlighter and like it a lot. I used to use the Google Code Prettify stuff (http://code.google.com/p/google-code-prettify/) and it worked well and was easy to integrate. It had some conflicts with my WordPress style though and I was too lazy to resolve it.
#03, Sep 06 2007
Dan
Hi Brian
Looks like you have done a fair bit of research. I liked the google syntax highlighter but i couldn’t be bothered pasting javascript and css all over the place.
I do most of my quick scripting in Vim with the vividchalk colorscheme. It has a great command called :TOhtml. Which is what i’ve settled on. It basically html’ifies whatever is in your buffer. Have a look at this post I did for an example of what it is capable of: Automating SVN Stuff with Ruby.
Cheers
#04, Sep 06 2007
Brian
Thanks for the feedback Jos and Alex. It is good to hear from developers who have used several of these.
@Dan
That is an interesting bit of functionality that Vim provides. I wonder if more editors contain that, and we do not realize it. I saw that Vim produces a pretty good helping of font tags in the code. Do you know if the export settings can be adjusted to use spans and/or CSS?
Brian
#05, Sep 06 2007
Alex Gorbatchev
I want to clarify something about Syntax Highlighter.
The purpose of the project is to allow bloggers to quickly and painlessly insert code snippets on their blogs.
I’m not sure what kind of a PC Jos Hirth is on, but it takes me about 1.5 seconds to render 600 lines (20kb) of code on my Core 2 Duo.
This however has never been the goal. This is the more typical use for which it was designed:
sameshirteveryday.com/2007/08/17/hello-facebook-in-rails/
Folks at YUI use it through out:
developer.yahoo.com/yui/examples/dragdrop/dd-handles.html
#06, Sep 06 2007
Brian
Hi Alex,
Thank you for taking the time to respond — your feedback is appreciated.
I cannot speak for Jos, but my own interpretation of the speed was a conclusion drawn simply by reading the Overview:
“SyntaxHighlighter uses regular expressions to parse the text. It’s not extremely fast, in fact, it’s pretty slow. If you are trying to highlight a few dozens lines of code, you won’t see any problems. Trying to highlight 10kb worth of text will result in JavaScript being aborted because of long execution time. “
#07, Sep 06 2007
dgurba
I use http://ultraviolet.rubyforge.org/ as my syntax hightlighting engine in html. I use a plugin for the SimpleLog Rails based blog software, called SyntaxHighlighter (not to be confused with the Google one?? :D)
Works great for me …
#08, Sep 07 2007
Jacob von Eyben
I have been looking for syntax highlighters as well the last couple of month and blogged about it as well yesterday.
The one I prefer is definitely the pure javascript Google Code Prettify library.
Easy to install and non intrusive.
Many bugs has been fixed over the past few month.
#09, Sep 07 2007
Nikhil
Hi Brian,
I am the author of ColourCode and well I would really like to thank you a lot for featuring it here. I am just 16 and seeing one of my projects being featured on other sites means a lot to me. I am really sorry that this version will be the last for a while, but I’ve got an important year in school and don’t get much time.
Thanks again.
#10, Sep 07 2007
Nikhil
Sorry for the double post but I have a few clarifications to make about ColourCode.
It is not real time, ColourCode is not for a server, it generates HTML files which I have uploaded to the site. There was no fast rendering speed on the server, it’s already rendered.
Sorry for spoiling your amazement.
#11, Sep 07 2007
Brian
Hi Nikhil,
You did a great job with ColourCode, and especially at such a young age you are to be commended for your efforts. I definately understand about priorities — study hard!
It is my mistake regarding ColourCode. I should have researched more in order to understand that it is not real-time. It is still a great tool, though. I am sure with a bit of initiative I could figure out how to plug it into my server.
Best of luck.
#12, Sep 07 2007
Alexey
One more simple to use highlighter with a lot of features: http://softwaremaniacs.org/soft/highlight/en/
#13, Sep 07 2007
Jos Hirth
@Alex
Well, I’m not sure what the issue was. By the looks of it the time it took wasn’t linear. Sometimes 100 lines were fine, sometimes it took over a minute to highlight a bit over 50 lines, and sometimes it didn’t even finish after a couple of minutes. (Well, that was on a 500mhz machine. SHJS was perfectly fine with that little processing power tho and it also uses regex.)
Unfortunately I wasn’t able to isolate the problem. I liked the line numbers and the copy to clipboard cheat tho. Great idea by the way.