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):

[Edit: not original results]

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;

Sorry, this blog does not support comments.

I used various blog hosting services since this blog was established in 2005, but unfortunately they turned out to be unreliable in the long term and comment threads were lost in unavoidable transitions. At this time I don't want to enable third-party services for comments since it has become obvious in recent years that these providers invariably monetize information about their visitors and users.

Please use the links in the page footer to get in touch with me. I'm available for conversations on Keybase, Matrix, Mastodon or Twitter, as well as via email.