#! /usr/bin/env perl # mdn - a simple web page generator. Call like this: # # % Markdown.pl file.md | mdn > file.html # # Typical Makefile: # # .SUFFIXES: .html .mdu # # .mdu.html: # Markdown.pl $< | mdn -s http://hack.org/mc/nav.css -n /mc/nav.html > $@ # # # Copyright (c) 2014 Michael Cardell Widerkrantz # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR # PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. use strict; use warnings; use Getopt::Std; # Stylesheet URL. Set with -s. my $stylesheet = ""; # Navigation bar include. Set with -n. my $nav = ""; my %opts; getopts("n:s:", \%opts); if ($opts{'s'}) { $stylesheet = $opts{'s'}; } if ($opts{'n'}) { $nav = $opts{'n'}; } print ' '; if ($stylesheet) { print "\n"; } my $title = ""; my $first = 1; my $pre = 0; while (<>) { if ($first) { # This is the first line. Remove the paragraph tags and use it as # the title. s/

//; s/<\/p>//; $first = 0; $title = $_; print "${title}\n\n\n"; if ($nav) { print "\n"; } print "

${title}

\n"; } elsif (m/
/)
    {
        $pre = 1;
        print;
    }
    elsif (m#
#) { $pre = 0; print; } elsif ($pre) { print; } elsif (!$pre && $_ !~ /^;/ && $_ !~ /^

;/) { print; } } print "\n\n\n";