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( );
else
transaction.Rollback( ); // no elements
}
catch {
transaction.Rollback( );
throw;
}
return result;