:
Skip Navigation
Resources Blog Blogging in Markdown With Embedded Code Syntax-Highlighting

Blogging in Markdown With Embedded Code Syntax-Highlighting

I've been using [Markdown][2] for a while now, but to date embedding code was a bit of a pain with Pebble and Marsedit. Sonatype has switched over to using Wordpress and I've installed a couple plugins to make working with Markdown and syntax-highlighted code very easy.

The first plugin is [Michael Fortin's][4] very cool [PHP Markdown Extra][3] which does the standard Markdown goodness but allows for many additions including allowing you to embed HTML in the Markdown.

This dovetails perfectly with the second plugin which is [Ryan McGeary's][5] [WP-Syntax][6] which allows you to use simple pre tags to markup your example code *inside* your Markdown.

So you would be blogging away and put something like this in your entry:

This is my markdown muck with a link to [Sonatype][1] and my code below:
<pre lang="java">public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}
<pre>
[1]: http://www.sonatype.com

And you'll end up with something spiffy like:
This is my markdown muck with a link to [Sonatype][1] and my code below:

public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}

With Wordpress and these two plugins loaded it makes blogging with example code a lot easier to deal with. Incidentally I tried the plugin for the Google Syntax Highlighter but it doesn't appear to work with WordpressMu (the multi-user version of Wordpress that Sonatype is using). The only thing I would like in the syntax-hightlighted code block is an easy way for the user to copy the sample code.
[1]: http://www.sonatype.com

[2]: http://daringfireball.net/projects/markdown/

[3]: http://michelf.com/projects/php-markdown/extra/

[4]: http://michelf.com/journal/

[5]: http://ryan.mcgeary.org/

[6]: http://ryan.mcgeary.org/wp-syntax/

Picture of Jason van Zyl

Written by Jason van Zyl

Jason is a co-founder and the former CTO of Sonatype.