# --------------------------
# readFile(fileName)
#
#  returns the complete file contents
#
sub readFile
    {
    my $fileName = shift;
    my $bunch;
    my $result;
    my $did;

    if(open(FILE,$fileName))
        {
        binmode FILE;           # Bite me, Windows! --dvb
        while(read(FILE,$bunch,32000))
            {
            $result .= $bunch;
            }
        close FILE;
        }

    return $result;
    }

# -----------------------
# writeFile(fileName,contents)
#
#  creates new file and writes entire
#  file contents. Return "ok" if so,
#  or "" if not.
#
sub writeFile
    {
    my $fileName = shift;
    my $contents = shift;
    my $did;

    #
    # Delete existing file, if any.
    #
    unlink ($fileName) if(-e $fileName);

    $did = open(FILE,">$fileName");
    if($did)
        {
        binmode FILE;           # Bite me, Windows! --dvb
        print FILE $contents;
        close FILE;
        return "ok";
        }

    printCommand("Trouble writing $fileName");
    return "";
    }


sub main($@)
{
    my $me = shift;

    my @argv = @_;
    my $template = $argv[0];
    my $md = $argv[1];

    my $templateS = readFile($template);

    $me =~ s/(.*)\/.*/$1/; # just the directory
    

    my $mdHtml = `perl $me/Markdown_1.0.1/Markdown.pl $md`;

    $templateS =~ s/--content--/$mdHtml/;

    print $templateS;

}

main($0,@ARGV);


