Tuesday, November 11th, 2008
If you already know what this is and just want to download it, click here to skip over my explanation.
Markdown, MarsEdit and Text Filters
On this blog I’m using the wonderful PHP Markdown Extra and PHP SmartyPants Typographer WordPress plugins by Michel Fortin. Both are WordPress-ready PHP reimplementations of John Gruber projects, and have been very helpful in allowing me to write unencumbered by HTML.
I’m also a big fan of MarsEdit,
Brent Simmons Gus Mueller Daniel Jalkut’s amazing blog editor, and most especially of its powerful Preview feature. You set up an HTML template that looks similar to your blog and MarsEdit will fill in that template and render your work in progress into a live-updating WebView.
It’s an amazing feature, made more amazing by the fact that you can define custom filters to run over your blog entry text before it’s displayed in HTML. This is extremely useful, since I write all my posts in Markdown and they are only ever transformed to HTML by WordPress at display time — they remain as Markdown in the database.
MarsEdit comes with a Markdown filter built-in, which I had used for a long time. However, it doesn’t support all of the features of PHP Markdown Extra, namely footnotes,1 which has increasingly gotten on my nerves. While writing my last post, OCMock and the iPhone, I was using footnotes enough that I decided the time to act had finally arrived.
Download it already!
This MarsEdit text filter will run PHP Markdown Extra 1.2.2 and PHP SmartyPants Typographer 1.0 over your posts before displaying them in the Preview window.
In case someone wants modify this to only run Markdown or SmartyPants, I’m providing this under the MIT license. Share and enjoy.
A Slight Quirk
MarsEdit’s text filtering system only allows you to write text filters with Perl. So the current setup is something like this:
- A Perl script slurps all its input and feeds it to a child PHP process.
- That PHP script runs
SmartyPants()and outputs the result.
- When the PHP script exits, the Perl script reads its child’s output buffer and outputs whatever was in there to MarsEdit.
This is certainly not the most ideal scenario, but unfortunately only one MarsEdit’s developer can solve. In the meantime feel free to use my code a basis for other bridges2 to other languages.
I would like to see MarsEdit’s text filtering improved, where the TextFilter bundle’s Info.plist specifies a file to run and MarsEdit simply executes that file, pipes the article to its input and reads its output. That decision is of course up to MarsEdit’s developer.