Changeset 16024


Ignore:
Timestamp:
2008-06-16T14:21:20+12:00 (16 years ago)
Author:
kjdon
Message:

indented the file properly

File:
1 edited

Legend:

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

    r15872 r16024  
    127127    my $self = shift (@_);
    128128    my ($htmlfile, $text) = @_;
    129        
     129   
    130130    # load in the file
    131131    if (!open (FILE, $htmlfile)) {
     
    152152    my $self = shift (@_);
    153153    my ($foundbody, $text, $handle) = @_;
    154    
     154    
    155155    my $line = "";
    156156    while (defined ($line = <$handle>)) {
     
    174174    }
    175175
    176    if ($self->{'input_encoding'} eq "iso_8859_1") {
     176    if ($self->{'input_encoding'} eq "iso_8859_1") {
    177177    # convert to utf-8
    178178    $$text=&unicode::unicode2utf8(&unicode::convert2unicode("iso_8859_1", $text));
     
    221221    return $section;
    222222}
    223        
     223
    224224# Will convert the oldHDL format to the new HDL format (using the Section tag) 
    225225sub convert_to_newHDLformat
    226226{
    227    my $self = shift (@_);
    228    my ($file,$cnfile) = @_;
    229    my $input_filename = $file;
    230    my $tmp_filename = $cnfile;
    231    
    232    # write HTML tmp file with new HDL format
    233    open (PROD, ">$tmp_filename") || die("Error Writing to File: $tmp_filename $!");
    234    
    235    # read in the file and do basic html cleaning (removing header etc)
    236    my $html = "";
    237    $self->HB_read_html_file ($input_filename, \$html);
    238    
     227    my $self = shift (@_);
     228    my ($file,$cnfile) = @_;
     229    my $input_filename = $file;
     230    my $tmp_filename = $cnfile;
     231    
     232    # write HTML tmp file with new HDL format
     233    open (PROD, ">$tmp_filename") || die("Error Writing to File: $tmp_filename $!");
     234    
     235    # read in the file and do basic html cleaning (removing header etc)
     236    my $html = "";
     237    $self->HB_read_html_file ($input_filename, \$html);
     238    
    239239    # process the file one section at a time
    240240    my $curtoclevel = 1;
     
    281281       
    282282        print PROD "<Section>\n\t<Description>\n\t\t<Metadata name=\"Title\">$title</Metadata>\n\t</Description>\n";
    283        
     283        
    284284        print PROD "-->\n";
    285          
     285       
    286286        # clean up the section html
    287287        $sectiontext = $self->HB_clean_section($sectiontext);
     
    324324    my ($file) = @_;
    325325    my $input_filename = $file;
    326  
     326    
    327327    if (-d $input_filename)
    328328    {
     
    353353    my $f_separator = &util::get_os_dirsep();
    354354   
    355    if ($dirname =~ /import$f_separator/)
     355    if ($dirname =~ /import$f_separator/)
    356356    {
    357         $test_dirname = $';
     357        $test_dirname = $'; #'
    358358   
    359359    #print STDERR "init $'\n";
     
    361361    while ($test_dirname =~ /[$f_separator]/)
    362362    {
    363         my $folderdirname = $`;
    364         $tmp_dirname = &util::filename_cat($tmp_dirname,$folderdirname);
    365             &util::mk_dir($tmp_dirname) if (!-e $tmp_dirname);
    366         $test_dirname = $';
     363        my $folderdirname = $`;
     364        $tmp_dirname = &util::filename_cat($tmp_dirname,$folderdirname);
     365        &util::mk_dir($tmp_dirname) if (!-e $tmp_dirname);
     366        $test_dirname = $'; #'
    367367    }
    368368    }
     
    377377        if ($self->{'old_style_HDL'})
    378378        {
    379         $hdl_output_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix");
    380         $hdl_output_filename = $self->convert_to_newHDLformat($input_filename,$hdl_output_filename);
     379        $hdl_output_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix");
     380        $hdl_output_filename = $self->convert_to_newHDLformat($input_filename,$hdl_output_filename);
    381381        }
    382382   
     
    388388    foreach my $file (@files)
    389389    {
    390         my $src_file = &util::filename_cat($base_dirname,$file);
    391         my $dest_file = &util::filename_cat($tmp_dirname,$file);
    392         if ((!-e $dest_file) && (!-d $src_file))
    393         {
    394             # just copy the original file back to the tmp directory
    395             copy($src_file,$dest_file) or die "Can't copy file $src_file to $dest_file $!";
    396         }
     390        my $src_file = &util::filename_cat($base_dirname,$file);
     391        my $dest_file = &util::filename_cat($tmp_dirname,$file);
     392        if ((!-e $dest_file) && (!-d $src_file))
     393        {
     394        # just copy the original file back to the tmp directory
     395        copy($src_file,$dest_file) or die "Can't copy file $src_file to $dest_file $!";
     396        }
    397397    }
    398398   
     
    401401    if ($self->{'tidy_html'})
    402402    {
    403         $tidy_output_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix");
    404         $tidy_output_filename = $self->tmp_tidy_file($hdl_output_filename,$tidy_output_filename);
     403        $tidy_output_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix");
     404        $tidy_output_filename = $self->tmp_tidy_file($hdl_output_filename,$tidy_output_filename);
    405405    }
    406406    $tmp_filename = $tidy_output_filename;
     
    410410        if (!-e $tmp_filename)
    411411    {
    412             # just copy the original file back to the tmp directory
    413         copy($input_filename,$tmp_filename) or die "Can't copy file $input_filename to $tmp_filename $!";
     412        # just copy the original file back to the tmp directory
     413        copy($input_filename,$tmp_filename) or die "Can't copy file $input_filename to $tmp_filename $!";
    414414    }
    415415    }
     
    418418}
    419419
    420    
     420
    421421# Will make the html input file as a proper XML file with removed font tag and
    422422# image size added to the img tag.
     
    429429    my $input_filename = $file;
    430430    my $tmp_filename = $cnfile;
    431  
     431    
    432432    # get the input filename
    433433    my ($tailname, $dirname, $suffix) = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$");
    434434
    435435    require HTML::TokeParser::Simple;
    436    
    437         # create HTML parser to decode the input file
    438         my $parser = HTML::TokeParser::Simple->new($input_filename);
    439 
    440         # write HTML tmp file without the font tag and image size are added to the img tag
    441         open (PROD, ">$tmp_filename") || die("Error Writing to File: $tmp_filename $!");
    442         while (my $token = $parser->get_token())
    443         {
    444         # is it an img tag
    445         if ($token->is_start_tag('img'))
    446         {
    447                 # get the attributes
    448                 my $attr = $token->return_attr;
    449 
    450                 # get the full path to the image
    451                 my $img_file = &util::filename_cat($dirname,$attr->{src});
     436   
     437    # create HTML parser to decode the input file
     438    my $parser = HTML::TokeParser::Simple->new($input_filename);
     439
     440    # write HTML tmp file without the font tag and image size are added to the img tag
     441    open (PROD, ">$tmp_filename") || die("Error Writing to File: $tmp_filename $!");
     442    while (my $token = $parser->get_token())
     443    {
     444    # is it an img tag
     445    if ($token->is_start_tag('img'))
     446    {
     447        # get the attributes
     448        my $attr = $token->return_attr;
     449
     450        # get the full path to the image
     451        my $img_file = &util::filename_cat($dirname,$attr->{src});
    452452       
    453                 # set the width and height attribute
    454                 ($attr->{width}, $attr->{height}) = imgsize($img_file);
    455 
    456                 # recreate the tag
    457                 print PROD "<img";
    458                 print PROD map { qq { $_="$attr->{$_}"} } keys %$attr;
    459                 print PROD ">";
    460         }
    461         # is it a font tag
    462         else
    463         {
    464             if (($token->is_start_tag('font')) || ($token->is_end_tag('font')))
    465             {
    466                 # remove font tag
    467                 print PROD "";
    468             }
    469             else
    470             {
    471                 # print without changes
    472                 print PROD $token->as_is;
    473             }
    474         }
    475         }
    476         close (PROD) || die("Error Closing File: $tmp_filename $!");
    477 
    478         # run html-tidy on the tmp file to make it a proper XML file
    479         my $tidyfile = `tidy -utf8 -wrap 0 -asxml $tmp_filename`;
    480 
    481         # write result back to the tmp file
    482         open (PROD, ">$tmp_filename") || die("Error Writing to File: $tmp_filename $!");
    483         print PROD $tidyfile;
    484         close (PROD) || die("Error Closing File: $tmp_filename $!");
     453        # set the width and height attribute
     454        ($attr->{width}, $attr->{height}) = imgsize($img_file);
     455
     456        # recreate the tag
     457        print PROD "<img";
     458        print PROD map { qq { $_="$attr->{$_}"} } keys %$attr;
     459        print PROD ">";
     460    }
     461    # is it a font tag
     462    else
     463    {
     464        if (($token->is_start_tag('font')) || ($token->is_end_tag('font')))
     465        {
     466        # remove font tag
     467        print PROD "";
     468        }
     469        else
     470        {
     471        # print without changes
     472        print PROD $token->as_is;
     473        }
     474    }
     475    }
     476    close (PROD) || die("Error Closing File: $tmp_filename $!");
     477
     478    # run html-tidy on the tmp file to make it a proper XML file
     479    my $tidyfile = `tidy -utf8 -wrap 0 -asxml $tmp_filename`;
     480
     481    # write result back to the tmp file
     482    open (PROD, ">$tmp_filename") || die("Error Writing to File: $tmp_filename $!");
     483    print PROD $tidyfile;
     484    close (PROD) || die("Error Closing File: $tmp_filename $!");
    485485   
    486486    # return the output filename
     
    535535    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
    536536    push(@{$hashArgOptLists->{"OptList"}},$options);
    537    
     537    
    538538
    539539    my $self = new ReadTextFile($pluginlist,$inputargs,$hashArgOptLists);
     
    609609}
    610610
    611  
     611
    612612# do plugin specific processing of doc_obj
    613613sub process {
     
    622622
    623623    if ($ENV{'GSDLOS'} =~ /^windows/i) {
    624       # this makes life so much easier... perl can cope with unix-style '/'s.
    625       $base_dir =~ s@(\\)+@/@g;
    626       $file =~ s@(\\)+@/@g;
     624    # this makes life so much easier... perl can cope with unix-style '/'s.
     625    $base_dir =~ s@(\\)+@/@g;
     626    $file =~ s@(\\)+@/@g;
    627627    }
    628628   
     
    10261026
    10271027    $filename = &util::filename_cat($base_dir, $filename);
    1028        
     1028   
    10291029    # Replace %20's in URL with a space if required. Note that the filename
    10301030    # may include the %20 in some situations
     
    10921092
    10931093    $before_hash = $self->eval_dir_dots($before_hash);
    1094                      
     1094   
    10951095    my $linkfilename = &util::filename_cat ($base_dir, $before_hash);
    10961096   
     
    11041104
    11051105    return ($type . $before_hash, $hash_part, $rl);
    1106    
     1106   
    11071107    } elsif ($link !~ /^(mailto|news|gopher|nntp|telnet|javascript):/i && $link !~ /^\//) {
    11081108    if ($before_hash =~ s@^/@@ || $before_hash =~ /\\/) {
     
    11291129            # $base_dir is already similarly "converted" on windows.
    11301130            if ($win_before_hash =~ s@^$base_dir/@@o) {
    1131               # if this is true, we removed a prefix
    1132               $before_hash=$win_before_hash;
     1131            # if this is true, we removed a prefix
     1132            $before_hash=$win_before_hash;
    11331133            }
    11341134        }
     
    12411241    # this assumes that ">" won't appear. (I don't think it's allowed to...)
    12421242    $html_header =~ /^/; # match the start of the string, for \G assertion
    1243  
     1243    
    12441244    while ($html_header =~ m/\G.*?<meta(.*?)>/sig) {
    12451245    my $metatag=$1;
     
    12841284        $tag='Creator';
    12851285    } elsif (!exists $find_fields{lc($tag)}) {
    1286          next; # don't want this tag
     1286        next; # don't want this tag
    12871287    } else {
    12881288        # get the user's preferred capitalisation
Note: See TracChangeset for help on using the changeset viewer.