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

0 comments suggest edit

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:

/// 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)
        ManualResetEvent waitHandle = 
                 as ManualResetEvent;
        if(waitHandle != null)
        _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?

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



8 responses

  1. Avatar for Colin
    Colin October 13th, 2004

    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?

  2. Avatar for Colin
    Colin October 13th, 2004

    I have a list of things I'd like to see added myself and both of your suggestions are on it. :)

  3. Avatar for Haacked
    Haacked October 13th, 2004

    Yes. I updated the text using the .TEXT admin tool. The textbox control that .TEXT uses is pure crap. Thanks for the heads up.

  4. Avatar for The .NET Guy
    The .NET Guy October 13th, 2004

    This is definitely one of the easiest to use tools to turn source code into syntax colored HTML. It's a...

  5. Avatar for David Boschmans' Weblog
    David Boschmans' Weblog October 14th, 2004


  6. Avatar for Needs Improvement
    Needs Improvement October 16th, 2004

    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...

  7. Avatar for Shital Shah
    Shital Shah November 11th, 2004

    Another quick and dirty way is to copy first in Word and then in HTML editor. It works!!

  8. Avatar for Haacked
    Haacked November 12th, 2004

    True, but that's too much work and I'm lazy. This add-in rocks and produces cleaner HTML.