Home > Miscellaneous > Site Update

Site Update

November 21, 2007

Since I am stuck waiting for VS2008 to finish downloading (again – currently at 35%), I thought that I would address something that has bugged me here for a while. I’ve never liked the option employed for showing code on the site. It’s ugly and bulky and does not handle line breaks, indenting, or syntax highlighting. Here is an example of what it used to look like:

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
lblIsFirstTime.Text = “This is the first call.”;
}
else
{
lblIsFirstTime.Text = “This is a PostBack”;
}
}

I hit the Google pavement today and found a WordPress Plugin for Code Highlighting. It installed easily and I went to work right away replacing the old code wrappers with this one. Now the examples should look like this:

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        lblIsFirstTime.Text = "This is the first call.";
    }
    else
    {
        lblIsFirstTime.Text = "This is a PostBack";
    }
}

I turned off line numbering, which is a plug-in wide setting, but I might fiddle with it to see if I can turn it on and off an runtime with an attribute. It would be handy for some examples to be able to reference line numbers. Also, I’d like to see if I can make it horizontally scrollable since some of the code wraps and isn’t as visually appealing (although it should copy and paste into your IDE just fine.)

I’ve gone back through all the old posts that show code and made this upgrade, so I hope you find them more usable now. Thanks to Dean Lee for a very useful plug-in.

UPDATE (94% downloaded):

I did correct the wrapping/scrollable issue mentioned above. This way, code actually looks as intended and preserves the original line break integrity.

I looked at the line number question also, but I do not see how I can make that change, at least not with some serious investigation, which I am not prepared to do. It functions well enough now as is. I also experimented with the color scheme, trying to make it closer to how Visual Studio highlights, but I actually like this way better. It has a few quirks though: for one, I cannot get “foreach” to color properly (even though it is in the Syntax array right next to “for”. I even tried reordering them in case it was a lookup bug, but no dice). There are a couple of other small items, but none of them detract from the code, so I’m not going to fuss with it anymore for now.

Advertisements
Categories: Miscellaneous
%d bloggers like this: