Page Options
You are here : News
MADdotNET News Minimize
Feb 24

Written by: Aaron Hoffman
2/24/2009 10:23 PM 

Source Code meets Cascading Style Sheets – makes baby

by Aaron Hoffman

 

If you’re a developer and you blog about code, you might find that from time to time you may wish to add a snippet of source code to your blog post.  There are may ways to do this, but these are a few of the easiest I’ve found.

#1 – Windows Live Writer Plug-In

If you are lucky enough to be using Windows Live Writer to write/create your blog posts, there is a handy plug-in, created by Omar Shahine, that simplifies the process of inserting source code into your blog post.  The originating source code can come from anywhere, without formatting, or can even be written on the spot, and will be transformed into beautifully formatted code, with line numbers and zebra stripes and everything!

 

1. First you will need to download and install Windows Live Writer.

2. After Windows Live Writer is setup correctly, you will need to download and install Omar’s Plug-In

image

 

3. After the plug-in has been installed (simple), re-open Windows Live Writer to start using the plug-in!

4. In the Bottom-Right corner of Windows Live Writer, in the “Insert” section, you should now see the “Code…” option.

image

5. Place the cursor where you would like to insert some source code and click the “Code…” link.  The following dialog box should open.

image

6. Paste or Write your code into the “Code” section and watch as it gets formatted right before your very eyes!  Choose the formatting options that you would like and click the OK button to finish this magic trick!

 

End Result:

   1:  public string ReturnString(string myString)
   2:  {
   3:      return myString;
   4:  }

 

 

#2 – Visual Studio Plug-In

Now some of the more “dedicated” programmers out there may have custom formatting within Visual Studio that you find to be far superior than anything Omar’s Plug-In can provide.  You may find this second option more appealing.  You may also find it helpful to get a little more sun (which is usually visible at around lunch time).  It is a plug-in for Visual Studio and is called, very simply, CopySourceAsHtml.  And does, well, exactly that.

 

1. Download and Install the CopySourceAsHtml plug-in.

2. After the plug-in has been installed a new “Copy as HTML…” option will available on the VS context menu (read: right-click menu)

image

3. If chosen, the “Copy As HTML” dialog box will appear.  Select all the options that appeal to you and Click OK.

image

4. Now go back to your Blog Writing Software of choice and Paste in the code.  Be sure to include the “source formatting” when pasting into your writing surface.  If that happens to be Windows Live Writer, use the “Edit >> Paste special…” option and select “Keep Formatting”.  Your beautiful source code will jump from the page!

image image

 

End Result:

    3 public string ReturnString(string myString)

    4 {

    5    return myString;

    6 }

 

 

#3 – Internet Plug-In

There are also lots of internet sites that will format your code for you… These are the first couple I found

http://www.manoli.net/csharpformat/

http://codeconverter.sharpdevelop.net/FormatCode.aspx

 

 

Summary

With a combination of these solutions, you should now have the ability to post beautiful looking source code wherever you may be.  Let me know how it goes or if you know of an even better solution that I did not cover here.

 

-Aaron Hoffman

 

--

http://gallery.live.com/liveItemDetail.aspx?li=1f57bd9b-a692-4593-9e9e-e2962d9c0eee&bt=9&pl=8

http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/

http://www.manoli.net/csharpformat/

http://codeconverter.sharpdevelop.net/FormatCode.aspx

--

Tags:
Categories Minimize
Search Blogs Minimize
Publish Dates Minimize
Print  

Copyright 2009 by Lance Larsen
Privacy StatementTerms Of Use