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
[code language=”csharp”]
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);
}
}
}
[/code]
WP-Syntax
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);
}
}
}
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.
Leave a Reply