Changeset 318 for trunk/gsdl


Ignore:
Timestamp:
1999-06-30T16:01:06+12:00 (25 years ago)
Author:
sjboddie
Message:

fixed a bug causing documents without <body> tags to have no text

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/HBPlug.pm

    r317 r318  
    3131sub HB_read_html_file {
    3232    my $self = shift (@_);
    33     my ($htmlfile) = @_;
     33    my ($htmlfile, $text) = @_;
    3434
    3535    # load in the file
    3636    if (!open (FILE, $htmlfile)) {
    3737    print STDERR "ERROR - could not open $htmlfile\n";
    38     return "";
    39     }
     38    return;
     39    }
     40
     41    my $foundbody = 0;
     42    $self->HB_gettext (\$foundbody, $text, FILE);
     43    close FILE;
     44
     45    # just in case there was no <body> tag
     46    if (!$foundbody) {
     47    $foundbody = 1;
     48    open (FILE, $htmlfile) || return;
     49    $self->HB_gettext (\$foundbody, $text, FILE);   
     50    close FILE;
     51    }
     52}
     53
     54sub HB_gettext {
     55    my $self = shift (@_);
     56    my ($foundbody, $text, $handle) = @_;
    4057
    4158    my $line = "";
    42     my $file = "";
    43     my $foundbody = 0;
    44     while (defined ($line = <FILE>)) {
     59    while (defined ($line = <$handle>)) {
    4560    # look for body tag
    46     if (!$foundbody) {
     61    if (!$$foundbody) {
    4762        if ($line =~ s/^.*<body[^>]*>//i) {
    48         $foundbody = 1;
     63        $$foundbody = 1;
    4964        } else {
    5065        next;
    5166        }
    5267    }
    53 
     68   
    5469    # check for symbol fonts
    5570    if ($line =~ /<font [^>]*?face\s*=\s*\"?(\w+)\"?/i) {
    5671        my $font = $1;
    57         print STDERR "HBPlug::HB_read_html_file - warning font $font used\n"
     72        print STDERR "HBPlug::HB_gettext - warning font $font used\n"
    5873        if ($font !~ /^arial$/i);
    5974    }
    60 
    6175
    6276    $line =~ s/<\/p>//ig;   # remove </p> tags
     
    6781    &html::convertcharentities ($line);
    6882
    69     $file .= $line;
    70     }
    71     close FILE;
    72 
    73     $file =~ s/\s+/ /g; # remove \n's
    74 
    75     return $file;
     83    $$text .= $line;
     84    }
     85    $$text =~ s/\s+/ /g; # remove \n's
    7686}
    7787
     
    144154
    145155    # read in the file and do basic html cleaning (removing header etc)
    146     my $html = $self->HB_read_html_file ($htmlfile);
     156    my $html = "";
     157    $self->HB_read_html_file ($htmlfile, \$html);
    147158
    148159    # create a new document
Note: See TracChangeset for help on using the changeset viewer.