Blogging C# code

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( );
      transaction.Rollback( ); // no elements
  catch {
    transaction.Rollback( );

  return result;

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s