Almost immediately after I announced Markdown.cgi, Adam pointed out that it was now impossible to get the source of a Markdown file, since the CGI was automatically rendering the files to XHTML.

To fix this, I have renamed my Markdown source files from .text to .markdown, and made the CGI look for .markdown files, instead of using the .text filename supplied in the URL. This minor change means the source is now available as .markdown, while the HTML version is available as .text. The Apache configuration does not have to change at all.

Additionally, I updated the comments to mention that Markdown.pl requires blank lines between block elements, so one should follow the initial title line.

The new version of Markdown.cgi is v1.2. You can download and rename Markdown.txt, but here it is for reference:

#!/bin/sh
# Markdown v1.2 2007/05/28
# Build an HTML page (with headers) from Markdown.pl output.

# v1.2: Source is .markdown, available without modification.
# Access as .text to get HTML version.

INCLUDES=/home/web/www.reppep.com/include
REALFILE=`dirname $PATH_TRANSLATED`/`basename $PATH_TRANSLATED .text`.markdown
TITLE=`head -1 $REALFILE | cut -f2`


echo "Content-type: text/html"
echo

cat $INCLUDES/head1.incl
echo $TITLE
cat $INCLUDES/head2.incl

# If we already have an H1, don't insert one.
if ! grep --silent '^# ' $REALFILE
 then
  echo -n '<h1>'
  echo -n $TITLE
  echo '</h1>'
  echo
fi

/usr/local/bin/Markdown.pl < $REALFILE

cat $INCLUDES/foot.incl

exit 0

# http://www.extrapepperoni.com/category/computers/markdown/
# http://daringfireball.net/projects/markdown/

# To use, copy Markdown.cgi (this wrapper, which you may have to rename
# from Markdown.txt) and Markdown.pl (from Daring Fireball) into your
# cgi-bin/ and make them executable
# ("chmod +x Markdown.cgi Markdown.pl"), set the correct path for
# INCLUDES below, and install head1.incl (HTML header up to <title>),
# head2.incl (HTML header starting with </title>), and foot.incl in
# that directory.

# Markdown.cgi reads the page's title from the first line, starting
# after the first tab and ending before the second.
# Your document's title should be inside an HTML comment, set off by tabs.
# Follow the title line with a blank line (Markdown.pl requires blank
# lines between block elements).
# The title line contains 5 parts:
# 1) the HTML comment open delimiter (less-bang-dash-dash)
# 2) a tab
# 3) the title text
# 4) a tab
# 5) the HTML comment close delimiter (dash-dash-greater)
# For example (not counting the # on the next line):
#<!--   Markdown.cgi: A Simple Wrapper for Markdown.pl  -->

# Add the following to your Apache httpd configuration
# (likely httpd.conf or a virtual host .conf file):
#   AddHandler markdown .text
#   Action markdown /cgi-bin/Markdown.cgi
#   AddType text/html .text
#   ScriptAlias /cgi-bin/ /home/web/www.reppep.com/cgi-bin/
#   AddType text/html .pl