<paraphrased>
Hi Colin, I've been using your excellent tool CopySourceCodeAsHtml for some time to post code to my blog. It's brilliant, and it keeps popping up in places such as the Visual Studio Hacks book, and at hanselman.com. Is it possible to use this tool in Visual Studio 2005? If not are there any plans to get this working?
</paraphrased>
The answer is finally "Yes." :)
I've just uploaded the first official release of CopySourceAsHtml for Microsoft Visual Studio 2005. This release has a leaner, meaner, refactored codebase that fixes a few minor defects and takes advantage of new features in Visual Studio 2005 and .NET 2.0. This will be the codebase that future releases will be built from.
I have to give credit for this release to Derick Bailey and Jason Haley for releasing their port of CopySourceAsHtml many months ago, filling the gap between my releases, and taking the pressure off of me. Thanks guys.
I've been getting a ton of comment spam lately, so much that moderating comments is becoming a pain. If you'd like to contact me about CopySourceAsHtml, but find comments on my blog are disabled, use the contact information in Support.txt or on the About tab of the add-in.
Colin
]]>James Avery mentioned CopySourceAsHtml in "Visual Studio Add-Ins Every Developer Should Download Now" in the December 2005 edition of MSDN Magazine. It's arguably the least useful add-in on the list, but it's great to be mentioned. Thanks James!
Derick Bailey ported CopySourceAsHtml to VS2005. I hope to release a version with VS2005 support and several improvements this week as a result. Thanks Derick!
Jeff Atwood has been working on his macro to copy source as HTML, provoking an arms race in copying-source-as-HTML, a race I intend to win. (OK, just kidding, there's room for both solutions.)
]]>CopySourceAsHtml 1.2.4 Installer (280 KB) (built and tested on VS.NET 2003)
CopySourceAsHtml 1.2.4 Source (38 KB)
CSAH 1.2.4 allows you to copy single-byte, double-byte, and Unicode characters from VS.NET. Previous versions only allowed you to copy single-byte and Unicode characters, and converted multi-byte characters to question marks. The new version should work properly for any DBCS codepage. Much of the credit for the new version goes to Qingbo Zhou for his suggestions, help debugging, and testing.
]]>I'm pretty sure this is the first time my software has been mentioned in a book. It's incredibly gratifying. :) :) :)
Colin
]]>Update: Fixed the links.
CopySourceAsHtml 1.2.3 Installer (280 KB) (built and tested on VS.NET 2003)
CopySourceAsHtml 1.2.3 Source (38 KB)
CSAH 1.2.3 generates heavier HTML than CSAH 1.2.2. I'm releasing 1.2.3 now because at least two popular blog engines (dasBlog and Blogger) introduce spaces, line breaks, and other formatting errors when converting the lighter 1.2.2-produced HTML to XHTML for their feeds. If you're experiencing these errors, you should upgrade to 1.2.3. If not, you should wait for 1.2.4.
Credits:
Colin
]]>
CopySourceAsHtml 1.2.2 Installer (287 KB) (built and tested on VS.NET 2003)
CopySourceAsHtml 1.2.2 Source (36 KB)
I've also set up a GotDotNet workspace for the project, in case anyone wants an older version of the tool.
CSAH now generates lighter HTML in all cases and much, much, much lighter HTML if word wrapping is disabled. For example, this block of code that previously weighed in at ~20KB now weighs in at ~10KB. That's good news if you're bandwidth-conscious.
I also fixed a few minor bugs that nobody reported.
Cheers,
Colin
]]>
CopySourceAsHtml 1.2.1 Installer (284 KB) (built and tested on VS.NET 2003)
CopySourceAsHtml 1.2.1 Source (33 KB)
CSAH now has a "Remove Indentation" checkbox on the "General" tab. If it's checked, CSAH will remove unnecessary indentation from the copied code, leaving it flush against the left border. CSAH now also:
Besides "Remove Indentation", I'm most excited about fixing the problems with background colors, because it means I can stop testing with these colors and change my settings back to the defaults:
Visual Studio .NET:

HTML:
32 #region Configuration Class Definitions
33 #region Enum Definitions
34 /// <summary>
35 /// Enum containing the mode options for the exceptionManagement tag.
36 /// </summary>
37 public enum ExceptionManagementMode
38 {
39 /// <summary>The ExceptionManager should not process exceptions.</summary>
40 Off,
41 /// <summary>The ExceptionManager should process exceptions. This is the default.</summary>
42 On
43 }
Ugh! :)
Colin
]]>
CopySourceAsHtml 1.2.0 Installer (283 KB) (built and tested on VS.NET 2003)
CopySourceAsHtml 1.2.0 Source (32 KB)
Update: I forgot to say anything about how to use CSAH. See this post and this post for background.
The biggest change in this release is that CSAH uses VS.NET's syntax highlighting and VS.NET's font and color settings automatically. If VS.NET can highlight it, CSAH can copy it, and your code should look the same in your browser as it does in your editor. Here are some examples:
1 <%@ Page Language="c#" Inherits="WebApplication1.WebForm1" AutoEventWireup="false" %>
2 <html>
3 <body>
4 <a href="<%=Something%>" target="_new">Something</a>
5 </body>
6 </html>
1 BODY
2 {
3 padding: 5px;
4 overflow: auto;
5 width: 95%;
6 max-height: 450px;
7 margin: 0px auto;
8 line-height: 125%;
9 border: silver 2px dotted;
10 }
12 protected void ParseRtf( string rtf )
13 {
14
15 int first;
16 int last;
17 int index;
18 int mark;
19 string controlWord;
20 bool hasParameter;
21 long parameter;
22
23 first = 1;
24 last = rtf.Length - 1;
25 for ( index = first ; index < last ; index++ )
26 {
27
28 switch ( rtf[index] )
29 {
30 case '{':
31 index += ParseOpeningBrace( rtf , index + 1 );
32 break;
33 case '}':
34 index += ParseClosingBrace( rtf , index + 1 );
35 break;
36 case '\\':
37 index++;
38 if ( char.IsLetter( rtf[index] ) )
39 {
40 mark = index;
41 while ( ( index < last ) && ( char.IsLetter( rtf[index] ) ) )
42 {
43 index++;
44 }
45 controlWord = rtf.Substring( mark , index - mark );
46 if ( ( index < last ) && ( ( char.IsDigit( rtf[index] ) ) || ( rtf[index] == '-' ) ) )
47 {
48 mark = index;
49 while ( ( index < last ) && ( ( char.IsDigit( rtf[index] ) ) || ( rtf[index] == '-' ) ) )
50 {
51 index++;
52 }
53 hasParameter = true;
54 parameter = Int64.Parse( rtf.Substring( mark , index - mark ) );
55 }
56 else
57 {
58 hasParameter = false;
59 parameter = 0;
60 }
61 if ( rtf[index] != ' ' )
62 {
63 index--;
64 }
65 index += ParseControlWord( rtf , index + 1 , controlWord , hasParameter , parameter );
66 }
67 else
68 {
69 index += ParseControlSymbol( rtf , index + 1 , rtf[index] );
70 }
71 break;
72 case '\r':
73 case '\n':
74 break;
75 default:
76 index += ParseLiteralText( rtf , index + 1 , rtf[index] );
77 break;
78 }
79 }
80 }
Other changes:
If you find CSAH useful, find a bug, have a suggestion, or want to review or contribute code, please let me know. I'd really like it if someone reviewed the code, actually, and helped me improve on it.
Cheers,
Colin
]]>Update: This version is no longer available for download. Download a newer version from this page.
After you install CopySourceAsHtml, two new commands will appear in the Options dialog under Environment > Keyboard:

and in the Customize dialog under Commands > Addins:

Copy ("Copy Source As HTML...") lets you select your language and formatting preferences before copying. CopyNow ("Copy Source As HTML") uses your previously selected preferences and copies immediately. If the active document's language isn't known, however, CopyNow simply calls Copy.
Copy ("Copy Source As HTML...") is added to the code window's context menu by default, but you can change which commands are added to the context menu in the registry (no editor, sorry) if you don't want to pollute your IDE:
HKEY_CURRENT_USER\Software\J.T. Leigh & Associates\CopySourceAsHtml\
AddCopyToContextMenu
AddCopyNowToContextMenu
If you find CopySourceAsHtml useful, find a bug, see room for improvement, or know of an existing add-in that provides the same functionality, please let me know.
Thanks,
Colin
]]>Update: This version is no longer available for download. Download a newer version from this page.
After you install CopySourceAsHtml, "Copy Source As HTML..." will appear in the code window's context menu:

When you click "Copy Source As HTML...", you'll be asked for language and formatting preferences. "Language", "Number From", and "Tab Width" are taken from the document. "Line Numbers", "Alternate Line Background", and "Embed Stylesheet" are stored in the registry.

When you click "OK", the source will be formatted according to your preferences and copied to the clipboard, ready to be pasted into your blog.
CopySourceAsHtml extends CSharpFormat, and I'm grateful to Jean-Claude for his excellent work. If you find CopySourceAsHtml useful, find a bug, see room for improvement, or know of an existing add-in that provides the same functionality, please let me know.
Thanks,
Colin
]]>