#!/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 "

Overriding metadata to generate partial XHTML

\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).