As I mentioned in Formatting HTML code snippets with Ten Ton Wrecking Balls, copying code to your clipboard in Visual Studio is often an excercise in futility if you want anything more than plain vanilla text. VS copies code to the clipboard with bizarro-world RTF formatting instead of the sane, simple HTML markup you might expect. This is true even of the brand spanking new VS.NET 2005.
Also, one criticism of the code that add-on is based on:
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?
I preserve the color scheme EXACTLY as VS.NET places it in the clipboard.
Plus I remove excessive indentation, which is great when you’re copying one method out of a class.
And I work with a single mapped hotkey, just like CTRL+C does.
It’s a great add-in (which I referenced in the comments to my original post), but it’s still an external add-in; all other things being equal, I prefer a lighter weight IDE macro that does the same thing. Easier to set up, easier to modify, more discoverable, etcetera.
A couple observations on differentiation:
My macro works for XML, HTML, and every other IDE filetype, in VS.NET 2003 and VS.NET 2005. Yours only works for C# or VB.NET code in VS.NET 2003.
You aren’t copying background colors. Try setting a background color (eg, for a string); it won’t show up in the resulting HTML. That’s the same problem I have, and it’s because the RTF inserted in the clipboard doesn’t have that information.
If you could come up with a way to truly retain background colors, I’d definitely be inclined to use your solution
and use it to supplement the font and color information from the RTF. They can indeed copy background colors. The release page has an example with some ugly colors:
your macro does has advantages over CopySourceAsHtml
Well, it’s a Macro. Different strokes. I do like that it’s a lighter weight solution (IMO)
But you should still grab the latest version and try it out.
But I did try it out! That’s what my last comments were based on.
Versions 1.2.1 and higher get font and color information from VS.NET
I previously installed the latest version 1.2.4 and I definitely didn’t get background colors for strings or numbers (the only two background color settings that I use).
That’s not good. I was particularly proud of those background colors. I’ll have to take some time next week to figure out why it’s not working, solve the VPC problem (it’s really the threading problem you work around in your macro, but I’ve only ever seen it manifest itself under VPC), and make a VS.NET 2005 version.
By doing so, you could remove all “span color:black” from your code (and the “span cleaner”), considering text will use the div’s color.
This is used to “reset” the color from whatever it was back to the default. Conversion from RTF to HTML means directly replacing RTF tags with HTML tags. And since RTF tags don’t have a strict begin/end relationship like those of HTML, it can get a little squirrelly!
Am I wrong ?
No, I think that’s a great suggestion. I tried it in the source, and miraculously, it works. I was afraid there would be mis-matched SPAN tags, but they all match.
I’ll update the source! (EDIT) I spoke too soon. When I tried this on more complex code snippets, I got mismatching SPAN tags. I’m doing a blanket replacement of RTF tags, and that only works if each element is replaced. If I “skip” replacing the cf0 (black) tags, you end up with mismatching SPAN tags and invalid HTML.
I found and liked this macro especially as it’s based on the IDE configuration and not a list of keywords, making it truly “WYSIWYG” in that sense.
However, I have problems with the HTML clipboard object it creates. It works fine in that FreeTextBox page, but not in a random text editor you’re using to make web pages? This really makes it less convenient than it could have been for me.
I can understand why one would find a HTML object to be nice, but for my uses, I wouldn’t mind it simply being copied as a text object as HTML code. Right now when I paste it into e.g. Notepad, EditPlus, or TopStyle Pro, I just get plaintext as if the macro didn’t do anything.
I might add that this HTML object mode is still very useful for the tools that support it though (I found OpenOffice.org to do), so by no means do I wish the feature should be exchanged. :-/ Probably more WYSIWYG HTML editors do as well, but “text” HTML editors may apparently not.