VS.NET Add-In For Source Code Formatting as HTML

Colin sent me an email pointing me to an add-in he wrote for VS.NET that allows you to copy selected source code to the clipboard as syntax highlighted HTML.

By selecting some code and right clicking the code editor, you'll see an option to Copy Source as HTML.

Selecting that menu item brings up a dialogue where you can configure some options. It's based on my favorite code to HTML formatter by Manoli.

Below is an example of a code snippet using this tool:

/// <SUMMARY>
/// Sets the stack trace for the given lock target 
/// if an error occurred.
/// </SUMMARY>
/// <PARAM name="lockTarget">Lock target.</PARAM>
public static void ReportStackTrace(object lockTarget)
{
  lock(_failedLockTargets)
  {
    if(_failedLockTargets.ContainsKey(lockTarget))
    {
        ManualResetEvent waitHandle = 
            _failedLockTargets[lockTarget] 
                 as ManualResetEvent;
        if(waitHandle != null)
        {
            waitHandle.Set();
        }
        _failedLockTargets[lockTarget] = new StackTrace();
        //TODO: Now's a good time to use your
        //favorite logging framework.
    }
  }
}

Colin, thanks for pointing me to this. This is freakin' awesome!

Now, if I could have a short-cut that would use the default options and immediately put the selected source in the clip-board, that would just rock my world. Also, one minor niggle I've had with the Manoli formatter is that the xml comments tags and the triplle slashes (such as ///

) should be gray to mimic VS.NET instead of all green. How hard would it be to fix that?

What others have said

Requesting Gravatar... Colin Oct 13, 2004 5:03 PM
# re: VS.NET Add-In For Source Code Formatting as HTML
It look like the angle brackets in the XML comments in your snippet weren't replaced with HTML entities. Did you edit the HTML in something that would have reformatted it?
Requesting Gravatar... Colin Oct 13, 2004 5:06 PM
# re: VS.NET Add-In For Source Code Formatting as HTML
I have a list of things I'd like to see added myself and both of your suggestions are on it. :)
Requesting Gravatar... Haacked Oct 13, 2004 5:07 PM
# re: VS.NET Add-In For Source Code Formatting as HTML
Yes. I updated the text using the .TEXT admin tool. The textbox control that .TEXT uses is pure crap. Thanks for the heads up.
Requesting Gravatar... The .NET Guy Oct 14, 2004 9:23 AM
# CopySourceAsHTML
This is definitely one of the easiest to use tools to turn source code into syntax colored HTML. It's a...
Requesting Gravatar... David Boschmans' Weblog Oct 14, 2004 3:30 PM
# CopySourceAsHTML
CopySourceAsHTML
Requesting Gravatar... Needs Improvement Oct 16, 2004 4:53 PM
# CopySourceAsHtml (Updated)
I've updated CopySourceAsHtml based on suggestions from Phil Haack and Eric Means, and on something Jake Good said about polluting his IDE. :) CopySourceAsHtml Installer (271 KB) (built and tested on VS.NET 2003) CopySourceAsHtml Source (32 KB) After you...
Requesting Gravatar... Shital Shah Nov 12, 2004 7:52 AM
# re: VS.NET Add-In For Source Code Formatting as HTML
Another quick and dirty way is to copy first in Word and then in HTML editor. It works!!
Requesting Gravatar... Haacked Nov 12, 2004 11:12 AM
# re: VS.NET Add-In For Source Code Formatting as HTML
True, but that's too much work and I'm lazy. This add-in rocks and produces cleaner HTML.

What do you have to say?

(will show your gravatar)
Please add 3 and 4 and type the answer here: