Syntax Highlighters

Published by on
Tags:

I have been using the Copy Code as HTML tool from http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/ to put code into my blog. This has been good but it generates a lot of extra HTML which I am not keen on. So instead I thought I would setup the Syntax Highlighter that I saw on Scott H blog to compare. The code for this is available from http://code.google.com/p/syntaxhighlighter/ and is a pure JavaScript tool. It nice that it does not clutter the HTML with extra markup and that it can cover a range of different languages.

Lets compare the two with come C#.

Firstly using Copy Code as HTML

    9 namespace Test

   10 {

   11     class Program

   12     {

   13         static void Main(string[] args)

   14         {

   15             //Say Hello

   16             Console.WriteLine("Hello World");

   17         }

   18     }

   19 }

 

And now with JavaScript:

 

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //Say Hello
            Console.WriteLine("Hello World");
        }
    }
} 

I like the markup of the second a lot more. The only problem I am having with the second version is that the BlogEngine editor I am using cleans up the preformatted text meaning I have to put in extra   to get the line indents. You also have to alter the editors JavaScript to stop it striping the name attribute from the pre tag. But all in all a much nicer output.

Add comment

 

Projects

Have you read?

Useful Links



Blogs by date