##
##  wml::fmt::text - Plain ASCII with Special Formatting Semantic
##  Copyright (c) 1997-2001 Ralf S. Engelschall, All Rights Reserved. 
##

#use wml::std::tags

<protect pass=2>
<:
#   the conversion function
sub wml_fmt_text {
    my ($arg) = @_;
    my ($buf);
    local (*FP);

    #   read the txt2html result
    open(FP, "$(WML_LOC_LIBEXECDIR)/wml_aux_txt2html $arg->{FILE}|");
    local ($/) = undef;
    $buf = <FP>;
    close(FP);

    #   cut out the body
    $buf =~ s|^.*<BODY>||is;
    $buf =~ s|</BODY>.*$||is;

    #   give headlines a more typographically strong look
    if (not $arg->{NOTYPO}) {
        $buf =~ s|^(<A NAME=".+?"><H([1-6])>)(.+?)(</H\2></A>)|$1<font face=\"Arial,Helvetica\">$3</font>$4|isg;
    }

    return $buf;
}
:>
</protect>

<define-tag text endtag=required>
<preserve notypo />
<set-var notypo=* />
<set-var %attributes />
<perl>
{
    my $tmpfile = "$(WML_TMPDIR)/wml.txt2html.$$.tmp";
    my $notypo = (qq|<get-var notypo />| eq '' ? 1 : 0);

    my $buf;
    <perl:assign:sq $buf>%body</perl:assign:sq>

    #   there is no reason to nest <text> tags, so the <perl:print>
    #   statement is unnecessary
    open(TXT, ">$tmpfile");
    print TXT $buf;
    close(TXT);

    <perl:print:
         "&wml_fmt_text({ FILE => $tmpfile, NOTYPO => $notypo })" />

    unlink($tmpfile);
}
</perl>
<restore notypo />
</define-tag>


##EOF##
