How do you copy code as HTML
I quickly want to tell you about a cool little plug-in to Visual Studio 2005 that I’ve been using to copy code to html and to keep the style from my editor.
It’s called CopySourceAsHtml, and while the website isn’t much to look at, and might not inspire confidence in the tool, I can assure you it’s a great little plug-in. After downloading the latest release (at time of writing 2.0.0) and installing, open Visual Studio and go to Tools -> Options -> Keyboard and in the “Show commands containing:” look for “copysource” and you should find JTLeigh.Tools.CopySouceAsHtml.Connect.Copy and JTLeigh.Tools.CopySouceAsHtml.Connect.CopyNow. Set a new shortcut for these (I’m only using .Copy and I’ve set it to Ctrl + H, Ctrl + C for “Html Copy”) and you’re ready to go. You can test it by selecting some code, hitting your shortcut and pasting the results into notepad. You’ll see it copies all the styles for you too.
public class Example
{
public Example()
{
//TODO
}
}
The main reason I like it, is because it keeps my tab spacing as well as my colours when I want to show a snippet of code on my blog.
William Brander points out the only problem I can see with this tool in that if you have a black background in Visual Studio then the text you copy will also have a black background when you view it as an HTML.
public class Example
{
public Example()
{
//TODO
}
}
Still, I think it’s pretty cool and I hope you find it useful too!



[…] #8221;button” id=”mybutton” value=”Click Me!” /> Damn! CopySourceAsHtml doesn’t work on Visual Studio Orcas, so you’ll have to forgive the lack of tex […]