CopySourceAsHtml: Html Source Formatting Utility

Last week I posted about a cool ASP.NET syntax highlighter that Wilco built that allows you to easily publish ASP.NET source online.  This works great for cases where you want to point to live source to generate syntax, although there are also sometimes needs to statically capture source formatting and embedd it in things like blog postings.

One question I've received a few times since then is what my "secret" is for generating source in some of my longer, code-intensive, blog posts.  Unfortunately my secret so far has been fairly lame -- I just use MS Word and copy/paste from VS into it (this preserves the color coding).  When I'm done, I then just copy/paste everything from Word into the rich-text control for my blog (which is based on .Text) and it preserves it.  The benefit of using Word is that it provides spell-checking (something I like to rely on), and it is pretty easy to use.  The downside is that Word generates some pretty ugly and verbose html.

In researching things more tonight, I can across Douglas Rohm's blog about source formatting options.  He pointed to a CopySourceAsHtml source formatting addin for VS 2005 that Jason Haley has written an installer for that you can download and use with VS 2005 here.  This is based on the origional VS 2003 based implementation done by Colin Coller

I'm planning on trying this out for some future blog posts and thought I'd pass it along to others who might find it useful.

Hope this helps,




  • I use Wilco's source formatter and then cut and paste into .Text. Works great and the code is pretty clean.

  • I have been using it and it is a very cool tool. Even a novice like me can make nice blog entrird with hilighted code.

  • CopySourceAsHtml is actually really cool, I can reccomend it! :-)

  • I use CopySourceAsHTML for my blog and it's the best but has one limitation:

    You can't copy HTML and Script codes of .aspx pages in VS 2005. You can copy them as XML but it's impossible to format correct colors such as:

    <% %> when they are in yellow.

  • I would also like to add a plug Jeff Atwood's FormatToHtml macro. I installed the macro in Visual Studio and all I need to do to post samples is:

    1) block select my sample

    2) Ctrl+C

    3) Double click the macro

    4) Paste into the IE.

    I found, however, that his version had some trouble with the ASP.NET forums because the forums strip styles off of <span> tags. I did a replaceall on all the <span> tags to <font> tags and this made it work nicely in both .Text and the forums.



  • I've been using it for a while when writing articles and in my blog. no complaints so far, very nice tool.

Comments have been disabled for this content.