Prism: lightweight, extensible syntax highlighter

In the process of wanting to start writing some more technical blogs, I was going to want to display code snippets and examples on my posts.

I did some searching and looking at several different implementations of getting this done. At the end of the day I ended up choosing Prism.

The main deciding factors that I had were that it was very easy to choose your options like theme, and languages, and some other cool features through plugins. Then you generate your .js and .css files that you can load directly into your site, very light weight.

One of the resources I found very useful while adding this functionality to my WordPress site was this tutorial . It walked me through adding the necessary files to my site and loading/ enqueue them to be picked up and loaded by the site, as I am pretty new to using a tool like WordPress to do everything for you, rather than building up the entire infrastructure myself.

Prism makes it very easy to just wrap your examples in a set of <pre> and <code> tags, and just tell it what language with a class name on your code tag.

<pre><code class="language-csharp">
… code
</code></pre>

Turns into

// HelloWorld.cs
using System;

public class HelloWorld
{
  public static void Main(string[] args)
  {
    Console.WriteLine("Hello, World!");
    for (int i = 0; i < args.Length; i++)
    {
       Console.WriteLine("{0}", args[i]); 
    }
  }
}