/[swish]/trunk/html/FormatResult.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/html/FormatResult.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 89 by dpavlin, Tue Aug 31 09:04:15 2004 UTC revision 107 by dpavlin, Sat Jul 9 13:14:25 2005 UTC
# Line 92  sub get_snippet { Line 92  sub get_snippet {
92  This is stand-alone function which does highlite. It cycle colors  This is stand-alone function which does highlite. It cycle colors
93  and generate html. Have in mind that it takes ref arguments.  and generate html. Have in mind that it takes ref arguments.
94    
95    C<@words> can also be array of arrays if you have alternative spellings
96    for each word (e.g. using C<Lingua::Spelling::Alternative>).
97    
98  =cut  =cut
99    
100  sub highlite_words {  sub highlite_words {
# Line 103  sub highlite_words { Line 106  sub highlite_words {
106          my @words = sort { length($b) <=> length($a) } @{$words_ref};          my @words = sort { length($b) <=> length($a) } @{$words_ref};
107    
108          # colors to highlite          # colors to highlite
109          my @colors = qw{#ffff66 #a0ffff #99ff99 #ff9999 #ff66ff};          my @colors = ('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff');
110    
111          # color offset          # color offset
112          my $i = 0;          my $i = 0;
113    
114          foreach my $w (@words) {          foreach my $w (@words) {
115                  $$snip_ref =~ s,(\b\Q$w\E),<span style="background: $colors[$i]; color:black;">$1</span>,gsi;                  if ($w =~ m/ARRAY/) {
116                            foreach my $ww (sort { length($b) <=> length($a) } @{$w}) {
117                                    $$snip_ref =~ s,(\b\Q$ww\E\w*),<span style="background: $colors[$i]; color:black;">$1</span>,gsi;
118                            }
119                    } else {
120                            $$snip_ref =~ s,(\b\Q$w\E\w*),<span style="background: $colors[$i]; color:black;">$1</span>,gsi;
121                    }
122                  $i++;                  $i++;
123                  $i = 0 if ($i > $#colors);                  $i = 0 if ($i > $#colors);
124          }          }

Legend:
Removed from v.89  
changed lines
  Added in v.107

  ViewVC Help
Powered by ViewVC 1.1.26