Please click this logo to help me get on their beta program:

Xobni outlook add-in for your inbox








4/2/2005

Blogging C# code

Filed under: General, Programming — Oliver Sturm @ 10:49 am - 3 years, 9 months ago

While I was trying what the best way would be to include C# code in my blog, I found that WordPress has problems with <pre> tags: it inserts <br> and <p> tags all over the place, trying to preserve XHTML validity. While I do like the validity idea, I don’t like the fact that it becomes more or less impossible to use the <pre> tag to publish code.

Looking around, I found the two modules that I need to get back proper <pre> functionality and a little nice highlighting for C#: the Syntax Highlighting with Enscript in WordPress plugin and a highlighting definition file for GNU enscript. These are easy to install together and render results like this (GPL code borrowed from the Linux kernel, drivers/hotplug/cpqphp_core.c):

static inline int is_slot66mhz (struct slot *slot)
{
        if (!slot || !slot->p_sm_slot)
                return 0;
	
        if (readb(slot->p_sm_slot + SMBIOS_SLOT_TYPE) == 0x0E)
                return 1;
	
        return 0;
}

or this in C#:

  bool result;
  Transaction transaction = StorageObject.BeginTransaction( );
  try {
    route.CurrentTransaction = transaction;
    result = route.CalculateElements( );
	
    if (result)
      transaction.Commit( );
    else
      transaction.Rollback( ); // no elements
  }
  catch {
    transaction.Rollback( );
    throw;
  }
	
  return result;

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Powered by WordPress
© Copyright 2005-2008 Oliver Sturm