Using Emacs and Markdown for WordPress postingPosted: March 21, 2009
While setting up this site (which is based on WordPress), I was evaluating
a few offline blog editors, and came upon MarsEdit and Ecto – both of which seem to be well-accepted commercial blog editors in the Mac
world. Both allow easy setup of the blog configurations, have a hassle-free
configuration, and allow a mail-inbox like access to previous posts.
My needs for the offline blogging tool are:
- Support WordPress (obviously)
- Support formatting in Markdown (the default WordPress formatting is atrocious). Note that you will need to enable Markdown syntax on your blog by using any of the plugins available for WordPress.
- Provide easy access to prior posts
- Have a decent text editor built-in
- Provide at least a subset of my current editing muscle-memory
However, I happen to be a Emacs fanatic, and perform majority of my day-to-day computing tasks in that tool (another post on this later). So I googled around a bit for the current state of blogging using Emacs, and voila! EmacsWiki pointed to the weblogger mode, which supports WordPress, and also handles Markdown formatting easily with the markdown mode. And to top it off, the code is open-source, which means that I can tinker and change the functionality when needed.
The next section describes the Emacs configuration needed to setup offline blogging using Weblogger mode.
- Rename both files, as the downloaded files have the incorrect suffix/extension .doc, which should be removed
- Add the renamed .el files in your Emacs load-path directory (e.g., site-lisp)
- Load the adding the following lines to your .emacs (i.e., the user-init) file: (require ‘weblogger)
- Restart Emacs, and initialize the blog-setup by issuing the command: M-x weblogger-setup-weblog and follow the prompts. Note that for WordPress, your blog URL needs to be suffixed with /xmlrpc.php
- If the setup worked fine till this point, you can fetch all previous posts by using the M-x weblogger-fetch-entries command, and
- Then access each entry using the command: M-x weblogger-next-entry or M-x weblogger-previous-entry
You can create a new post by using the weblogger-start-entry command. This brings up a mail-like buffer, where the subject line denotes title of the post, and the body is the actual post content.
At this point, you can enter your post-entry (using Markdown syntax, if you have enabled the WordPress plugin, or else by using raw HTML). Once the content is completed, press C-x C-s to save the file, which will also post the entry to your blog.
Caveat: The current Emacs mode does not provide any categorization mechanism, which still needs to be done via the admin interface on your blog. Categorization is actually supported. While composing the post, use the Keywords: meta-header to provide names of existing categories, separated by comma.
This setup has been working pretty well for me, and lets me use all the other
Emacs functionalities as well. In summary, the pros and cons are:
- Enables me to blog from within Emacs, and use all the Emacs-goodness the platform brings
- Emacs is a multi-platform editor, and I can blog from any system I have access to (i.e., not tied to my Mac)
- I can tweak the behavior of the system by directly accessing the code, if needed
- This is a free and open-source solution
- No preview feature. This can be a problem for some.. You can use the <a href=”http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip”>markdown</a> along with markdown mode to perform easy previews using the system default browser. Use the markdown-preview command in Emacs to access this feature. Another alternate mechanism is using the Maruku tool, which requires Ruby to be installed. Ruby is installed by default in OS X
Note that Ecto and MarsEdit are both capable systems, and are more Mac-like. I do have the trial versions downloaded, and will be trying both out over the next couple of weeks as well.