For ages I've been struggling with pasting code into my blog and having it look readable, let alone nice. I searched around the web for a solution and found a couple of Visual Studio add-ins (CopySourceAsHTML, Output Source Files in HTML Format), but they were not what I was looking for. Having a VS add-in to do this is cool, but it is not always the best solution.
- I am not always on my personal development machine and I may not have the add-in or even Visual Studio all together installed.
- I don't only post C# code. I also post SQL, XML, HTML, etc. It would be nice if the solution could cater for all of them.
After searching a bit more online I came across this cool solution, which is an online source code formatter. It can do C#, VB, SQL, XML, HTML and even MSH! It also has some nice little extras, such as alternate row highlighting and line numbers.
Unfortunately it didn't play nice with my blog. The output makes use of the "<pre>" HTML tag, which didn't agree with the engine my blog uses, so quite simply I couldn't use it. More searching online didn't yield any better alternatives, so I decided to take the plunge, crank open the code and mess with it until it works. While I was there I took the opportunity to fix a couple of CSS bugs related to line numbers and alternate row highlighting.
Here is the result.
I've made it available to everyone, so enjoy. You will notice that the biggest change is that by default the "<pre>" tag is not used in the HTML output, but the extra option allows you to turn that functionality back on.
Many thanks to manoli for making the source code available.