I’ve spent the morning getting highlighting working with WordPress and thought it might be worth the writeup to detail my steps since there was one significant gotcha when using published information.
I’m using the SyntaxHighlighter Evolved plugin which you can search for on the Plugins page of your WordPress installation. Install that plugin first.
Once that’s done, you’ll need to follow the directions for creating third party brushes for Syntax Highlighter. Specifically, you’re going to need to create your own plugin, which is pretty simple to do. Here’s what I did.
First, create a new folder in your plugins folder called clojurebrush. In that folder, create a php file with the following code (feel free to change the details at the top):
[php]<?php
/*
Plugin Name: SyntaxHighlighter Evolved: Clojure Brush
Description: Adds support for the Clojure language to the SyntaxHighlighter Evolved plugin.
Author: Brett Bim
Version: 1.1.0
Author URI: http://yourblog.com/
*/
// SyntaxHighlighter Evolved doesn’t do anything until early in the "init" hook, so best to wait until after that
add_action( ‘init’, ‘syntaxhighlighter_clojure_regscript’ );
// Tell SyntaxHighlighter Evolved about this new language/brush
add_filter( ‘syntaxhighlighter_brushes’, ‘syntaxhighlighter_clojure_addlang’ );
// Register the brush file with WordPress
function syntaxhighlighter_clojure_regscript() {
wp_register_script( ‘syntaxhighlighter-brush-clojure’, plugins_url( ‘shBrushClojure.js’, __FILE__ ), array(‘syntaxhighlighter-core’));
}
// Filter SyntaxHighlighter Evolved’s language array
function syntaxhighlighter_clojure_addlang( $brushes ) {
$brushes[‘clojure’] = ‘clojure’;
$brushes[‘clj’] = ‘clojure’;
return $brushes;
}
?>[/php]
Note that this is the same file structure as the directions from the previous link with the exception of removing the version number from the wp_register_script() function call. That’s the thing that ate up a good chunk of my morning.
Once that’s done, you’ll need the JavaScript brush file for Clojure from Travis Whitton. Dump that into the clojurebrush folder that you created above. Go to your Plugins in WordPress and activate your new plugin. Once that’s done, you should have syntax highlighting in WordPress enabled.
May 4, 2010 at 11:29 am
Thanks Brett! Very nice.