Using Live Writer with the WordPress SyntaxHighlighter plugin

Since this is likely to be a code-heavy blog and I had a bit of trouble getting the syntax highlighting to work with Live Writer, this seems to be a good first blog post.

In the end I decided to use one WordPress plugin and one Live Writer plugin.  They seem to work great together so far.  Both plugins make use of brilliant SyntaxHighlighter package by Alex Gorbatchev (you don’t need to install this.. it comes with the WordPress plugin).

The WordPress plugin is called SyntaxHighlighter Evolved by Viper007Bond.  Install this plugin into WordPress the usual way (wp-admin > Plugins > Add New).  After installing and activating the plugin, go into the plugin settings for SyntaxHighlighter Evolved and check the box that says "Always load all language files".  Save the new configuration.

The Live Writer plugin is called the PreCode Code Snippet Manager by Anthony Bouch.  Install this plugin into Live Writer.

I’ve tried several of the Live Writer code snippet plugins, and this is the only one I have found that correctly handles the PRE tags and doesn’t munge up my double quote symbols.

Once you have both plugins running, you can insert code into your blog posts from directly inside Live Writer.  Simply click on "PreCode Snippet" from the Live Writer sidebar, set your language and options, and insert your code!  The results looks like this:

// PHP Comment
function phpFunction() {
    echo "I'm a PHP Function";
}

 

// Java Comment
public class SomeJavaClass {

    public static void main(String args[]) {
        System.out.println("Java foo!");
    }

}

 

<!-- XML Comment -->
<SomeXMLObject>
    <SomeField someAttribute="foo">
        <SomeElement>Foobar!</SomeElement>
    </SomeField>
</SomeXMLObject>

2 thoughts on “Using Live Writer with the WordPress SyntaxHighlighter plugin”

Leave a Reply

Your email address will not be published. Required fields are marked *