Syntax Highlighting for blog posts. Visual Studio 2008 plugin.

The are several syntax highlighting services available in the Internet, but many Visual Studio developers does not know about one really handy free and open source plug in for Visual Studio 2008.

http://copysourceashtml.codeplex.com/

CopySourceAsHtml is an add-in for Microsoft Visual Studio 2008 that allows you to copy source code, syntax highlighting, and line numbers as HTML. CSAH uses Visual Studio's syntax highlighting and font and color settings automatically. If Visual Studio can highlight it, CSAH can copy it, and your source should look the same in your browser as it does in your editor.

It's very easy to use, just select code which you want to highlight for your blog post and click Copy as HTML.

 

 then you will see configuration menu, which is does not actually require any changes and ready to use by default.

 

After OK, only one thing you need to do is to Paste code html which is now in the buffer to your blog edit html view, and the result will be like this:

 

 

using System.Web;

using System.Web.Mvc;

using System.Web.UI;

 

namespace MvcApplication3

{

    public partial class _Default : Page

    {

        public void Page_Load(object sender, System.EventArgs e)

        {

            // Change the current path so that the Routing handler can correctly interpret

            // the request, then restore the original path so that the OutputCache module

            // can correctly process the response (if caching is enabled).

 

            string originalPath = Request.Path;

            HttpContext.Current.RewritePath(Request.ApplicationPath, false);

            IHttpHandler httpHandler = new MvcHttpHandler();

            httpHandler.ProcessRequest(HttpContext.Current);

            HttpContext.Current.RewritePath(originalPath, false);

        }

    }

}

 

 

 

I found it very handy, easy and fast to use.

 

 

P.S. and yeah it's working for .aspx pages too, but in this case there is no context menu option, you need to select code and click in Visual Studio menu Edit->Copy As HTML

 

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

 

<asp:Content ID="changePasswordTitle" ContentPlaceHolderID="TitleContent" runat="server">

    Change Password

</asp:Content>

 

<asp:Content ID="changePasswordContent" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Change Password</h2>

    <p>

        Use the form below to change your password.

    </p>

    <p>

        New passwords are required to be a minimum of <%=Html.Encode(ViewData["PasswordLength"])%> characters in length.

    </p>

    <%= Html.ValidationSummary("Password change was unsuccessful. Please correct the errors and try again.")%>

 

    <% using (Html.BeginForm()) { %>

        <div>

            <fieldset>

                <legend>Account Information</legend>

                <p>

                    <label for="currentPassword">Current password:</label>

                    <%= Html.Password("currentPassword") %>

                    <%= Html.ValidationMessage("currentPassword") %>

                </p>

                <p>

                    <label for="newPassword">New password:</label>

                    <%= Html.Password("newPassword") %>

                    <%= Html.ValidationMessage("newPassword") %>

                </p>

                <p>

                    <label for="confirmPassword">Confirm new password:</label>

                    <%= Html.Password("confirmPassword") %>

                    <%= Html.ValidationMessage("confirmPassword") %>

                </p>

                <p>

                    <input type="submit" value="Change Password" />

                </p>

            </fieldset>

        </div>

    <% } %>

</asp:Content>

 

No Comments