Better reST–WordPress Pipeline

23:15 Tue 28 Jul 2009
[, , , , , , , ]

Last week I posted about my setup for going from reStructuredText to WordPress. It involved a shell script, some Python scripts, and the pbpaste and pbcopy commands. It worked, but it was a little on the convoluted side.

Now I have a slightly better process, and one that I will have used to publish this post.

The previous version was launched via Quicksilver and operated on the contents of the clipboard; the new version is run from the command line—or, even better, from within jEdit—and operates on a file. It:

  • Runs the contents of the file through my reST–Wordpress script, which uses rst2wp and some customized other Python scripts.
  • Submits the transformed text to WordPress via python-blogger, a script for doing blog XMLRPC operations in Python.
  • Runs svn add on the file.
  • Opens the WordPress Edit Draft page for the submitted post.

So, the previous steps for me were:

  • Write post in reStructuredText in jEdit.
  • Select all.
  • Copy.
  • Invoke a shell script via Quicksilver.
  • Switch to WordPress new post tab in Firefox.
  • Paste.
  • Fiddle with the post settings slightly.
  • Post.

While the new ones are:

  • Write post in reStructuredText in jEdit.
  • Save.
  • Invoke a jEdit macro to run the Python script from within the editor.
  • Switch to WordPress new post tab in Firefox.
  • Fiddle with the post settings slightly.
  • Post.

(As a bonus, this version also adds the file to Subversion.)

The jEdit macro seems

These are the components necessary to make it work:

  • Docutils—of course, to handle the reStructuredText
  • rst2wp, which I’ve modified a little for my own purposes.
  • python-blogger, to talk to WordPress in Python.
  • WordPress with XMLRPC enabled so that software can talk to it.
  • A short script of my own that pulls the pieces together. (This uses os.subprocess, so Python 2.4 or better is required)
  • A jEdit macro to run the script from the last step within the editor.

I’m pretty happy with it, and I think it should be fairly cross-platform, which is important to me as I’d like to take this whole setup with me if I switch environments in future.

Leave a Reply