olivier deheurles

Just another programming weblog

Syntax highlighting

Since there are good chances that I post code samples in the blog, I wanted a good way to format them and I think I found one. There’s a WordPress plug-in which uses this Syntax Highlighter written in JavaScript (the Highlight occurs client-side).

For my personal use, a good syntax highlighter should :

  • be easy to use, I don’t want to have to make lots of manipulations to output a well formatted code,
  • allow easy editing : if my code is escaped with lots of HTML tags and CSS, it won’t be very convenient to work with while editing a post,
  • allow visitor to copy paste it, without having the same kind of HTML tags disturbance,
  • support a least C# and XML,
  • output formatted code in RSS.

Let see how this plug-in render :


// Hello1.cs
public class Hello1
{
   public static void Main()
   {
      System.Console.WriteLine("Hello, World!");
   }
}

Not too bad. Let’s see with a XML document now :


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section
            name="castle"
            type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
    </configSections>

    <castle>
        <components>
        </components>
    </castle>
</configuration>

Fine !

I just see one problem with that solution : since Syntax Highlight is processed client side (JavaScript), the code will not be highlighted in RSS :-(

I found an other solutions that can do the job : http://www.manoli.net/csharpformat/format.aspx is an online service that can encode source code snippets in HTML. The annoying point with that is that it generates quite a lot of CSS/HTML and I fear the day where I will have to update some piece of code surrounded with 5465451 HTML tags…

1 Comment so far

  1. Kylie Batt May 19th, 2010 2:19 am

    как раз в тему!!!!)))))))))))))))))))))))))))))))))…

    For my personal use, a good syntax highlighter should :

    be easy to use, […….

Leave a reply

You must be logged in to post a comment.