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

# Download CopySourceAsHtml 8/25/2008 9:50 AM Scott on Writing

# Download CopySourceAsHtml 8/25/2008 9:55 AM ASPInsiders

CopySourceAsHtml (CSAH) is a free Visual Studio Add-In created by Colin Coller that turns Visual Studio

# Download CopySourceAsHtml 8/25/2008 10:20 AM BusinessRx Reading List

CopySourceAsHtml (CSAH) is a free Visual Studio Add-In created by Colin Coller that turns Visual Studio

# Download CopySourceAsHtml 8/25/2008 3:10 PM Readed By Wrocław NUG members

CopySourceAsHtml (CSAH) is a free Visual StudioAdd-In created by Colin Coller that turns Visual Studio

# re: Displaying Formatted Source Code in a Web Page 2/13/2009 11:12 PM Matt

Scott,

Know any way to copy .aspx source code to HTML and not just code-behind code??

I'm not a hard-core programmer but want to write some tutorials on the .aspx source code like page headers, meta-data tagging methods etc...

Thank you,
Matt

# re: Displaying Formatted Source Code in a Web Page 2/14/2009 11:35 AM Scott Mitchell

Matt, you can use CSAH for generating HTML for the declarative markup in the .aspx portion of an ASP.NET page, although it's not straightforward. When I select declarative markup I do NOT see the "Copy Source as Html" option in the context menu. However, after selecting the declarative markup I can go to the Edit menu and choose "Copy Source as Html".

This worked for me using CSAH 3.0 and Visual Studio 2008.

Thanks

# re: Displaying Formatted Source Code in a Web Page 8/12/2009 5:47 AM חברת ניקיון

i also I do NOT see the Copy Source as Html

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

My Links

Ads Via DevMavens

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<March 2010>
SMTWTFS
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Comment Stats

DayTotal% of Total
Sunday 2056.8%
Monday 42514.1%
Tuesday 51917.2%
Wednesday 55618.4%
Thursday 58019.2%
Friday 54718.1%
Saturday 1886.2%
Total 3020100.0%

Hour1Total% of Total
12:00 AM 782.6%
1:00 AM 812.7%
2:00 AM 682.3%
3:00 AM 822.7%
4:00 AM 692.3%
5:00 AM 1264.2%
6:00 AM 1193.9%
7:00 AM 1816.0%
8:00 AM 1926.4%
9:00 AM 1585.2%
10:00 AM 1886.2%
11:00 AM 1936.4%
12:00 PM 2016.7%
1:00 PM 1846.1%
2:00 PM 1695.6%
3:00 PM 1354.5%
4:00 PM 1153.8%
5:00 PM 1073.5%
6:00 PM 1013.3%
7:00 PM 1073.5%
8:00 PM 923.0%
9:00 PM 882.9%
10:00 PM 913.0%
11:00 PM 953.1%
Total 3020100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.00160
Monday 4.80384
Tuesday 4.04477
Wednesday 7.39680
Thursday 6.26676
Friday 5.07466
Saturday 4.78177
Total 5.403020

Hour1 Entry MadeAvg.Total
12:00 AM 5.2937
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 3.8550
8:00 AM 3.72134
9:00 AM 6.06297
10:00 AM 5.63276
11:00 AM 4.22194
12:00 PM 6.16351
1:00 PM 3.09133
2:00 PM 4.89230
3:00 PM 7.67322
4:00 PM 4.00108
5:00 PM 6.07170
6:00 PM 4.64116
7:00 PM 8.95188
8:00 PM 8.63164
9:00 PM 5.00115
10:00 PM 6.31101
11:00 PM 4.5732
Total 5.403020

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


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles