goozbach

Syndicate content
Updated: 1 hour 22 min ago

MultiMarkdown Apache handler.

Sat, 2008-08-16 18:00 -
The "What?" and the "Why?" I've been a fan of the MultiMarkdown for quite a while now. I keep all of my important notes in this format, which is easy to write with just a simple text editor. I wanted... goozbach

Everybody Should go to UTOSC -- 2008

Sat, 2008-08-16 18:00 -
This year I'm not going to be able to make it to the Utah Open Source Conference. This makes me sad. So to get everyone excited. I'm FINALLY blogging about the videos which were taken of my presentation at last... goozbach

MultiMarkdown Apache handler.

Mon, 2008-08-11 21:07 -
The "What?" and the "Why?"

I've been a fan of the MultiMarkdown for quite a while now. I keep all of my important notes in this format, which is easy to write with just a simple text editor.

I wanted to be able to copy or sync my *.mark files to my web server and have them automatically be rendered as XHTML. I looked into a couple of ways of doing this. One of which is the Text::MultiMarkdown::ApacheHandler Perl module Apache handler. The downside is that this handler doesn't work out of the box in Apache2.2.

Read on to see my solution. I've also seen a cgi based apache handler done by reppep as chronicled here. The only problem is that he's using the original Markdown. I've long been a fan of the extended syntax, and output formats I can get from MultiMarkdown. So I've build a similar script to what reppep has done.

The "How?" Prereqs.

You'll need at least these Perl modules installed on your system.

  • File::Slurp
  • CGI
  • Text::MultiMarkdown

You'll also need Apache and mod_cgi installed.

The script

The CGI script I use is pretty straightforward. Here it is in it's entirety:

#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use Text::MultiMarkdown qw/markdown/; use File::Slurp qw/slurp/; my $file = $ENV{PATH_TRANSLATED}; my $text = slurp($file); my $mark; if (param('_text')) { print header('text/plain'); print $text; } else { print header; $text .= "\n\n[See the Source](?_text=1)\n\n"; if (param('_partial')) { ##TODO test for Format: complete header and warn my @lines = split /\n/, $text; if (@lines = grep (!/^([Ff][Oo][Rr][Mm][Aa][Tt]):\s*(.*)$/, @lines)) { print "<h4>Overriding metadata to generate partial XHTML</h4>\n"; } $text = join("\n",@lines); $mark = markdown($text); } else { $mark = markdown($text, { document_format => 'complete' } ); } print $mark; } __END__ =head1 Name multmd.pl =head1 DESCRIPTION A simple cgi script which is used as an action handler for the Apache HTTP Server. =head1 USAGE Place this file into your cgi-bin directory and add a stanza like this to /etc/httpd/conf/httpd.conf Action markdown /cgi-bin/multimd.pl AddHandler markdown .mark AddType text/html .mark Now any MultiMarkdown file you serve which has the extenstion .mark will automatically get rendered as xhtml. This script will honor all of the metadata you place in your markdown file with the exception of the Format: header which is always assumed to be complete =head1 OVERRIDES You can override the default actions of this script by passing some parameters encoded into the URL. =head2 TEXT Pass a parameter of _text=1 to get the raw MultiMarkdown file. http://example.com/foo.mark?_text=1 =head2 PARTIAL To override the default action of rendering an entire XHTML file, pass a parameter of _partial=1 to get just the partial XHTML. http://example.com/foo.mark?_partial=1 This will override any Format: headers in your source MultiMarkdown file. And the default format of the handler (which is complete).

Place this script into your cgi-bin directory and make sure it's executable by your web server's process. I named mine multimd.pl. Here's a downloadable link of multimd.pl

The config

To make your new script do exactly what you want it to (render *.mark files as XHTML to the browser), you'll need to modify your Apache config. I placed this config section into a file named /etc/httpd/conf.d/multimarkdown.conf

Action markdown /cgi-bin/multimd.pl AddHandler markdown .mark AddType text/html .mark Testing

Make sure your Apache configs are proper by running the command apachectl configtest. If all checks ok, you should be good to restart your Apache server, upload a MultiMarkdown-formatted file to your web server with the extension of *.mark, and see it rendered in it's full XHTML glory.

You can see examples of how this MultiMarkdown handler works by clicking on the links below.

Presentation on presentations

After action report from my presentation

As you have probably noticed, there is a "See the source" link on each rendered page. This is part of the CGI script I created. Add the parameter _text=1 to the url and the handler passes the MultiMarkdown source file straight to the client without any rendering, like so.

I hope you enjoy the simplicity of editing decent web documents in a simple format.

Next time I'll share how I keep all of my files in sync using Bazaar-ng and bzr-push-and-update.

Everybody Should go to UTOSC -- 2008

Thu, 2008-07-31 15:20 -

This year I'm not going to be able to make it to the Utah Open Source Conference. This makes me sad. So to get everyone excited. I'm FINALLY blogging about the videos which were taken of my presentation at last year's event.

You can watch an interview which I gave for OpensourceTV here:

The first part of my presentation on Virtualization here:

and the second part here:

Powerful Presentations

Thu, 2008-07-03 07:00 -
I'm doing a presentation for ALE Central this Thursday Here's the blurb In our professional lives we often spend a great deal of time in one sort of presentation or another. A PowerPoint slide show for work, a story to... goozbach

Great Quote -- Sir Ken Robinson

Fri, 2008-06-27 11:00 -
I had a great idea I've been a big fan of the TED talks for a while now and listening to them just inspired me to do something new. Every so often I will post to this blog one of... goozbach

Good "Hack Music"?

Fri, 2008-06-27 11:00 -
I work in an office with four other people. This is a good thing when it comes to communicating and working together. However it can be a bit detrimental when it comes to entering into "The Zone". To combat this,... goozbach

Thoughts while working with a Cisco switch

Fri, 2008-06-27 11:00 -
I've just racked and installed my newest toy at the datacenter: a Cisco Catalyst 4948 switch . Prior to working here I have never had the experience of working with a Cisco switch other than to plug myself into it... goozbach

Using Virt-clone

Fri, 2008-06-27 11:00 -
Using the libvirt tool virt-clone is pretty simple to make a new guest image.virt-clone -o ORIGINAL_GUEST -n NEW_GUEST_NAME -f /new/guest/disk/fileThere's not much more to it.  Virt-clone takes care of all the unique stuff (uuid, mac address, etc).... goozbach

I am a genious (SIC)

Fri, 2008-06-27 11:00 -
I have two Debian servers, One is the old one, running on hardware that dell is no longer supporting (without us shelling out again) in a couple months. The other -- the new one-- is a virtual instance I have... goozbach