#!/usr/bin/perl -w
# doc_munge
#   Grab everything between the BODY tags and add Mason <%text> tags.
#   Munge URLs into our form.
# $Id: doc_munge,v 1.3 2006/11/27 19:39:23 fenner Exp $

local $/ = undef;

my $contents = <STDIN>;

$contents =~ s/^.*<BODY[^>]*>//is;
$contents =~ s!</BODY.*!!is;

$contents =~ s!href="/([^"]*)"!fixref($1)!ge;

$contents = '<%text>' . $contents . '</%text>';

print $contents;

sub fixref {
    my $file = shift;

    $file =~ s!\./!!g;
    $file =~ s!/!-!g;

    return 'href="' . $file . '"';
}
