Archive

Posts Tagged ‘syntax’

Syntax Highlighting

January 1st, 2008

While I haven’t posted anything technical on this blog yet, I certainly intend to continue posting technical information, including code samples. When I moved to wordpress, I decided to get a plugin to handle my syntax highlighting.

I found two, neither worked. I don’t know if there were conflicts with my version of wordpress, if it was some other plugin or script in my template or just poorly executed configuration on my part. Either way, I decided to look for alternatives and I’m glad I did.

I found the Iris Syntax Highlighter through a link on the YUI Blog. Iris Syntax Highlighter is not a wordpress plugin and it doesn’t integrate directly into your site (at least not the way I’m using it), but there is a .NET component and a command line tool. For now, I am planning on using the web based interface to format my code. I have loaded a copy of the core CSS file on this site to keep my markup for code samples as light as possible.

Here’s a short snippet of JavaScript code that shows a simple alert, just to demonstrate the highlighting capabilities:

var showMessage = function(msg){
//call window alert to display supplied message
window.alert(msg);
}

showMessage('This is a test');
1
2
3
4
5
6

The generated code uses a table and pre tags. The first time I pasted the code above, the formatting wasn’t quite right. I spent a few minutes of trial and error with line breaks and moving code around before giving up and pasting it over again. The second time, everything showed up alright. It appears that when the code was pasted the first time, additional line breaks were added in the <pre> areas. I’m sure I messed something up, but when you do this and the code looks strange the first time, save yourself the time and see if pasting it over again fixes the problem.

Iris supports Vim syntax definitions, which allows it to support over 460 different syntaxes! Pretty impressive. If you have a need to create HTML versions of formatted code, you should check it out. If you are here looking for technical information… stay tuned, now that I can format code again, I will be posting code samples in C#, JavaScrip, HTML and anything else that pops into my head.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tools , ,