Markdown Redux

As I’ve mentioned previously, I’ve recently started using Markdown to format my blog entries. After using it for a few posts, I honestly think it’s lowered the “friction” it takes to compose an entry. When I first saw it, my immediate reaction was, “Why? We already have Textile.” However, Textile is a tool to “mark up” plain text to be formatted as (x)html, where Markdown is a tool to render plain text as (x)html. In other words, Markdown strives to remove the need to insert markup; instead it uses existing plain text idioms, especially from email. It doesn’t have as many features as Textile, but it has all the features I use. It also handles certain things much more easily; I’m not sure I ever figured out how to mark up multi-paragraph blockquotes in Textile.

The Blosxom interface in the current beta releases (1-3) apply markdown formatting to every post. In my previous post on Markdown, I offered a updated version that used the Blosxom meta plugin and a “meta-markup” header to enable Markdown on a per post basis. John Gruber, author of Markdown, stated on the Markdown mailing list that he’d rather make this behavior optional. I agreed, and have produced version 2 of my Markdown-Blosxom patch:

Update 3-25-04: John Gruber has released Beta 4 of Markdown, which incorporates (and improves) these changes. The code patch below is now deprecated; go grab a new (post-beta-3) copy of Markdown. :

#### Blosxom plug-in interface ##########################################

# Change $blosxom_always to 0 to use "meta-markup: markdown" story
# headers to enable Markdown on a per-story basis
my $blosxom_always = 1;

#don't change; auto-detects
my $blosxom_hasmeta;

sub start { 1; }
sub filter {
    $blosxom_hasmeta = defined(%meta::);
sub story {
    my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;

     if ($blosxom_always or 
         ($blosxom_hasmeta and 
          defined($meta::markup) and 
          $meta::markup =~ /^\s*markdown\s*$/i))  {
        $$body_ref  = Markdown($$body_ref);

Notes: * Install is as before. Replace the existing Blosxom plug-in interface with the code above; remember to rename to Markdown when you put it in your plugins directory.

  • By default, it will always apply Markdown (as it was originally). Even if the Meta plugin is present, we can’t assume the user wants to use it to control Markdown. If you want to use meta-markup, set $blosxom_always to 0.

  • I check for the presence of meta instead of assuming it’s avilable. If blosxom_always is 0, but meta plugin is not available, Markdown will never be invoked.

  • the check for meta occurs in blosxom interface’s filter() method. start() is a poor choice because Markdown could be loaded before meta (and will be by default, which is alphabetical). filter() will run for every plugin after all plugins are loaded.


  • the meta-markup check is now a case insensitive regex.

  • No longer applying markdown processing to the story title. This was causing <p> tags wrapped around the title, which is not appropriate in places like RSS feeds.

Second Update:

  • Astute reader ArC points out that if you are using meta but a post has no meta-markup in the header, the check of $meta::markup would cause perl to complain. I’ve added a defined($meta::markup) test.

Both comments and pings are currently closed.

One Response to “Markdown Redux”

  1. Sebbo Says:


    Thanks for the blosxom titles fix. Considering that Daring Fireball has a good laugh at Movable Type for essentially the same faux pas, I was kinda surprised to find the bug there when I tried installing Markdown.