There’s a lot to know about sharing code via WordPress. The most popular plugins for handling syntax highlighting leverage open source code. Here is what I looked at.
WP-Syntax is based on GeSHi.
Code Prettify is based on Javascript code prettifier.
SyntaxHighligher Evolved is based on SyntaxHighlighter, which is used by WordPress.com.
GeSHi strives to avoid conflicts with others. I have found that SyntaxHighlighter Evolved doesn’t play nicely with Code Prettify.
Ultimately, it came down to these two.
- SyntaxHighlighter Evolved
- WP-Syntax
In either case, what you can embed in a blog post is pretty limited. Gist, CodePen, .Net Fiddle, and JSFiddle are all probably better for more involved samples. That all said, I’ll go with WP-Syntax.
2023-01-06 Update: Yeah, I know. Now that I've moved the blog from WordPress to Ghost, this is irrelevant. Especially since code is natively supported in Markdown. But for prosperity here is the original code sample:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
public class Program
{
public static void Main()
{
IEnumerable eventTypes = Enum.GetValues(typeof(TraceEventType)).Cast();
foreach(TraceEventType eventType in eventTypes)
{
Console.WriteLine("{0}: {1}", eventType, (int)eventType);
}
}
}