Changeset 31415


Ignore:
Timestamp:
2017-02-15T03:51:39+13:00 (4 years ago)
Author:
Georgiy Litvinov
Message:

Modified html links pointed to different section in the same document.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm

    r30022 r31415  
    631631        unless $self->{'no_metadata'};
    632632    }
    633    
     633    $self->replace_section_links($doc_obj);
    634634    } else {
    635635
     
    11261126}
    11271127
     1128sub replace_section_links {
     1129    my $self = shift(@_);
     1130    my ($doc_obj) = @_;
     1131    my %anchors;
     1132    my $top_section = $doc_obj->get_top_section();
     1133    my $thissection = $doc_obj->get_next_section($top_section);
     1134    while ( defined $thissection ) {
     1135        my $text = $doc_obj->get_text($thissection);
     1136        while ( $text =~ /(?:(?:id|name)\s*=\s*[\'\"])([^\'\"]+)/gi ) {
     1137            $anchors{$1} = $thissection;
     1138        }
     1139        $thissection = $doc_obj->get_next_section($thissection);
     1140    }
     1141    $thissection = $top_section;
     1142    while (defined $thissection) {
     1143        my $text = $doc_obj->get_text($thissection);
     1144        $text =~ s/(href\s*=\s*[\"\'])(_httpsamepagelink_#)([^\'\"]+)/$self->replace_link_to_anchor($1,$2,$3,$thissection,$anchors{$3})/ige;
     1145        $doc_obj->delete_text( $thissection);
     1146        $doc_obj->add_utf8_text( $thissection, $text );
     1147        $thissection = $doc_obj->get_next_section ($thissection);
     1148    }
     1149}
     1150sub replace_link_to_anchor {
     1151    my $self = shift(@_);
     1152    my ($href_part,$old_link,$identifier,$current_section,$target_section) = @_;
     1153    if (length $target_section && $current_section ne $target_section){
     1154        return $href_part . "javascript:goToAnchor(\'" . $target_section . "\',\'" . $identifier . "\');" ; 
     1155    }
     1156    return $href_part . $old_link . $identifier ;
     1157}
    11281158
    11291159sub format_link {
Note: See TracChangeset for help on using the changeset viewer.