CodeHTMLer is a utility written by Weshaggard and available here. The utility allows you to convert code to HTML for insertion into a website or blog. It happens to be the tool I use for code on this site. I know, I know. There are many tools already available for this but I prefer CodeHTMLer for several reasons.
- It supports multiple languages.
- The HTML is partially configurable via the XML file it loads.
- Some code elements can be ignored rather than having to generate style information for everything.
- Can use either existing CSS styles or inline styles.
- It is fast.
The only issue I had with it was that I wanted to use it inside Visual Studio. Being a developer I did the logical thing and wrote an addin for it. The addin was originally written for VS2008 and the updated for VS2010. The attached code runs under VS2010. The addin wraps CodeHTMLer and adds the following features.
- Copy as HTML is exposed as an option in the editor.
- A UI is added to allow you to change the options in the XML file to control how HTML is generated.
- Uses the VS code model to determine which language definition to use for formatting so you can format VB one way and C# another, for example.
I only ran into a couple of problems with CodeHTMLer. These mainly revolved around the manner in which it expected to be used. I had to modify (and annotate) the areas I changed. Furthermore I needed a few additional options for controlling formatting so I extended the language definition code to add a few extra attributes along with the serialization logic. So the version that is included here is a modified version of the one available from CodePlex. As a final note the attached language definition file is modified to support how VS names languages. The original version did not use the same name for C# as VS.
IMPORTANT: I don’t take credit for CodeHTMLer or any of its source. I only take credit for the addin code. Please support the original author for CodeHTMLer.
The current project is for VS2010 but you can recompile the code if you want a VS2008 version. To use this code extract the binaries to your addin directory (%My Documents%\Visual Studio 2010\Addins). In VS you probably need to enable the loading of the addin via the Tools\Addin Manager command. If it does not show up then you might need to modify the addin file to force a re-registration. The addin shows up as an item in the Tools menu and as a context menu option when you right-click in the code area.