Creating a SublimeText plugin to publish to WordPress

The Plan

As you may have noticed over the past few blogs, I tend to take a lot of notes at seminars/conferences etc. At the last one I attended I took along my teeny old samsung netbook and just used sublimetext in “zen” mode to take notes with a nice, basic, “white on black” UI.

I took my notes using the markdown syntax (when I remembered to) but the process of getting that to my blog was a little longer than I’d like. I’ve since added the Markdown on Save plugin, which will automatically convert a wordpress post from markdown syntax to html.

I thought I’d have a crack and speeding up the process by hooking sublimetext into wordpress, either letting the wordpress plugin do the markdown conversion or perhaps do that from sublimetext itself.

A Little Background

What’s SublimeText?

Only the most awesome text editor EVER (at the moment until I find another one I like better). It can be extended with plugins written in python, which gave me a great excuse to learn a basic chunk of a new language.

What’s Markdown?

A lightweight markup language for writing human-readable content which can be compiled into HTML

What’s Python?

A functional scripting language

What’s WordPress?

An insanely popular free blog engine; sometimes even used as a CMS. It has an XML RPC API.

I initially wanted to use the “Markdown On Save” plugin to automatically convert my markdown content to HTML as it gets inserted into wordpress, so decided to self host wordpress since blgos on wordpress.com don’t allow for plugins; the easiest route to do this is with Azure websites.

How I hooked this all together

  1. download sublimetext2
  2. set up an azure account
  3. set up a new website in azure using the gallery to choose blog->wordpress
  4. use google one helluva lot to get
    i. wordpress metablog api
    ii. LOADS of python scripting help

###
Unfortunately, I can’t seem to get the “markdown on save” plugin to fire when I post remotely; I’m pretty sure there is support for this as the documentation for the plugin mentions support for 3rd party apps and there are comments referring to xmlrpc in the code.

I couldn’t manage to work it out though, so have opted for the option of implementing markdown using python within sublimetext. The script I’m using for this is the fantastic python-markdown2 library; I just had to copy the lib/markdown2.py file into the sublimetext “plugins/user/” directory (or anywhere in “plugins” actually) and reference it from my script.

other random reference material

  • pyblog
  • Fiddler & Windows Live Writer: for finding out what the actual parameter being used to specify “tags” is; mt_keywords
Creating a SublimeText plugin to publish to WordPress