I come across many websites and blogs these days that still don't format their code well when posting it online. Whenever I see a site with poorly styled code I wonder how good of a programmer they actually are and how little effort they put into their site. For those of us with Visual Studio this task has been made pretty simple thanks to a tool called CopySourceAsHtml. This simple tool integrates with Visual Studio to allow you to copy out its syntax highlighting to html exactly as you see it. Since Visual Studio adds syntax highlighting to many common file types it makes its easy to generate html from almost any of your source code.
I found this tool to be the easiest to use because it doesn't require you to install or change anything on your website. It also creates html that displays well in most browsers. Some browsers like Internet Explorer will ignore tags like <pre> which is used to mark text as preformatted. CopySourceAsHtml doesn't use <pre> tags it mostly uses <p> paragraphs and <span> spans. It also lets you add specific styling to certain sections making it more dynamic. A link to the author's website for more details and a download are below. Also included is a link to convert the add-on to run in Visual Studio 2008.
Links
http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/- Copy Source As HTML
http://developers.de/blogs/andreas_erben/archive/2007/08/01/using-copysourceashtml-with-visual-studio-2008-beta-2.aspx- Visual Studio 2008 Fix