Scott on Writing

Musings on technical writing...

Displaying Formatted Source Code in a Web Page

In my last blog entry you may have noticed that my code snippet looks rather spiffy. Here, let me show off just how spiffy my source code formatting is!

    1 private ProductsTableAdapter _productsAdapter = null;

    2 protected ProductsTableAdapter Adapter

    3 {

    4     get {

    5         if (_productsAdapter == null)

    6             _productsAdapter = new ProductsTableAdapter();

    7 

    8         return _productsAdapter;

    9     }

   10 }

   11 

   12 [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]

   13 public Northwind.ProductsDataTable GetProducts()

   14 {

   15     return Adapter.GetProducts();

   16 }

Whee, that was fun and easy. Easy because of a free Visual Studio plug-in (one for VS.NET, one for VS 2005) I found earlier in the week, Colin Coller's CopySourceAsHtml (CSAH). Just highlight source code in Visual Studio, right-click and choose Copy as Html. Colin's plug-in then converts the highlighted code into HTML that accurately reflects your Visual Studio's appearance settings. A quick and easy way to show your code on your blog or in online articles!

The only downside I see is that it appears that you can't CopyHtmlAsHtml. That is, when I highlight markup in an ASP.NET page, there's no Copy as Html option in the context menu.

posted on Friday, June 30, 2006 9:51 AM

Feedback

# re: Displaying Formatted Source Code in a Web Page 6/30/2006 12:00 PM Scott Mitchell

CORRECTION: You _can_ CopyHtmlAsHtml, it's just not available from the context menu. In short, in an ASP.NET page you need to highlight the text and then go up to the Edit menu...

# re: Displaying Formatted Source Code in a Web Page 6/30/2006 6:04 PM Jeff Atwood

Give my VS.NET HTML conversion macro a shot. I think it's easier than installing an .exe, and you get your choice of HTML or text HTML in the clipboard.

http://www.codinghorror.com/blog/archives/000429.html

It also has the advantage of working with any file type that VS.NET understands.

# re: Displaying Formatted Source Code in a Web Page 7/1/2006 11:03 AM Gail

will this work for VWD?

# A good JavaScript Syntax Higlighter 7/2/2006 7:48 PM Marcos Meli

I use a JavaScript class to highlight code examples:

http://www.dreamprojections.com/syntaxhighlighter

Is excellent because you only paste the code and don´t need to worry how it look, also has other options to show th eline or columns numbers, etc.

Some examples

http://filehelpers.sourceforge.net/example_easy.html
http://filehelpers.sourceforge.net/example_progress.html

Cheers
Marcos

# re: Displaying Formatted Source Code in a Web Page 7/4/2006 4:17 AM jokiz

i was surprised that you only knew the said addin which was featured in msdn mag months ago. good thing you blogged about it since i haven't seen jeff atwoord's macro version.

# Displaying Formatted Source Code in a Web Page 8/24/2006 7:13 PM Heybo Blog

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

Add To Your Reader

My Links

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<May 2008>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1866.8%
Monday 37913.9%
Tuesday 45316.7%
Wednesday 50418.5%
Thursday 53519.7%
Friday 49418.2%
Saturday 1666.1%
Total 2717100.0%

Hour1Total% of Total
12:00 AM 652.4%
1:00 AM 682.5%
2:00 AM 622.3%
3:00 AM 742.7%
4:00 AM 572.1%
5:00 AM 1033.8%
6:00 AM 1084.0%
7:00 AM 1585.8%
8:00 AM 1716.3%
9:00 AM 1475.4%
10:00 AM 1716.3%
11:00 AM 1816.7%
12:00 PM 1886.9%
1:00 PM 1696.2%
2:00 PM 1605.9%
3:00 PM 1324.9%
4:00 PM 1073.9%
5:00 PM 923.4%
6:00 PM 913.3%
7:00 PM 963.5%
8:00 PM 833.1%
9:00 PM 782.9%
10:00 PM 792.9%
11:00 PM 772.8%
Total 2717100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.54144
Monday 5.22339
Tuesday 4.28419
Wednesday 7.67637
Thursday 6.90607
Friday 5.48411
Saturday 5.33160
Total 5.842717

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.35107
9:00 AM 6.32278
10:00 AM 6.47246
11:00 AM 4.41181
12:00 PM 6.88330
1:00 PM 3.00111
2:00 PM 5.41222
3:00 PM 8.64285
4:00 PM 4.0589
5:00 PM 5.92154
6:00 PM 4.52113
7:00 PM 9.67174
8:00 PM 9.80147
9:00 PM 5.05111
10:00 PM 5.4265
11:00 PM 4.5732
Total 5.842717

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles