Thursday, March 22, 2007


Source Code Highlighting for Blogger Posts: CopySourceAsHTML

If you have read any of my blog posts that contain C# source code, you will have no doubt noticed the varied, or lack of indentation! It wasn't intentional. I've actually sat down and tried to post entries with lots of source code and then given up in frustration.

I've been using CopySourceAsHTML 2.0, a great little add-in for Visual Studio 2005, for some time but Blogger would lose the indentation when I swapped between the HTML and compose views. I played around with it for a bit today and found settings that seem to work:

I also tried turning off "Embed styles" and placing the small amount of required CSS into the blog template, but I had no luck getting this to work. Let's just say I'm not the world's greatest CSS wizard (Lvl 1, AC10, small kitten...).

CopySourceAsHTML made it into James Avery's must read MSDN article "Ten Essential Tools: Visual Studio Add-Ins Every Developer Should Download Now".

I also came across Jean-Claude Manoli's Code Format Tool which does the job nicely but misses out on the 'Teal' Type colouring that you get from CopySourceAsHTML. It's worth downloading his lean source code for a peek; a very nice piece of coding. Doug Rohm posted a syntax colouring round-up here.


Powered by Blogger