Changeset 16301


Ignore:
Timestamp:
2008-07-04T12:57:26+12:00 (16 years ago)
Author:
ak19
Message:

sub tmp_area_convert_file--called to replace a plain text source file with html--is now updated to ensure that the html generated in this case is enclosed in proper html tags

File:
1 edited

Legend:

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

    r16104 r16301  
    9191    # in from another plugin)
    9292    if (!defined $metadata->{'Title'}) {
    93     my ($title) = $$textref;
    94     $title =~ /^\s+/s;
    95     if (defined $self->{'title_sub'} &&
    96            $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;}
    97     $title =~ /^\s*([^\n]*)/s; $title=$1;
    98     if (length($title) > 100) {
    99         $title = substr ($title, 0, 100) . "...";
    100     }
    101         $title =~ s/\[/[/g;
    102         $title =~ s/\[/]/g;
    103         $title =~ s/\</&#60;/g;
    104         $title =~ s/\>/&#62;/g;
     93    my $title = $self->get_title_metadata($textref);
    10594    $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
    10695    }
     
    11099    # insert preformat tags and add text to document object   
    111100    $self->text_to_html($textref); # modifies the text
    112     $doc_obj->add_utf8_text($cursection, $$textref); #$doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
     101    $doc_obj->add_utf8_text($cursection, $$textref);
    113102
    114103    return 1;
     104}
     105
     106sub get_title_metadata {
     107    my $self = shift (@_);
     108    my ($textref) = @_;
     109   
     110    my ($title) = $$textref;
     111    $title =~ /^\s+/s;
     112    if (defined $self->{'title_sub'} && $self->{'title_sub'}) {
     113    $title =~ s/$self->{'title_sub'}//;
     114    }
     115    $title =~ /^\s*([^\n]*)/s; $title=$1;
     116    if (length($title) > 100) {
     117    $title = substr ($title, 0, 100) . "...";
     118    }
     119    $title =~ s/\[/&\#91;/g;
     120    $title =~ s/\[/&\#93;/g;
     121    $title =~ s/\</&\#60;/g;
     122    $title =~ s/\>/&\#62;/g;
     123   
     124    return $title;
    115125}
    116126
     
    200210    }
    201211    close(TEXT); # close the file
    202    
    203     # convert the text
     212
     213    # Get the title before embedding the text in pre tags
     214    my $title = $self->get_title_metadata(\$text);   
     215
     216    # Now convert the text
    204217    $self->text_to_html(\$text);
    205        
    206     #print STDERR "****output_filename: $output_filename\n";
    207     #print STDERR "****text: $text\n";
    208 
     218   
    209219    # try creating this new file writing and try opening it for writing, else exit with error value
    210220    unless(open(HTML, ">$output_filename")) {  # open the new html file for writing
     
    212222    return ""; # no filename
    213223    }
    214     # write the html contents in text out to the file
    215     print HTML $text;
     224    # write the html contents of the text (which is embedded in <pre> tags) out to the file with proper enclosing tags
     225    print HTML "<html>\n<head>\n<title>$title</title>\n</head>\n<body>\n";
     226    print HTML $text;
     227    print HTML "\n</body>\n</html>";
    216228    close HTML;
    217229
Note: See TracChangeset for help on using the changeset viewer.