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.