Perlfect Solutions
 

[Perlfect-search] Highlight Matches ... Title Sometimes Got Highlighted Also - Bugs?

Daniel Naber perlfect-search@perlfect.com
Mon, 16 Sep 2002 14:39:18 +0200
--Boundary-00=_2Ddh98ubKAjvvnv
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On Monday 16 September 2002 11:32, Morten Wulff wrote:

> Yes, this seems to be the default behavior. I have made a small patch
> which fixes this 'problem'. Find it here:

I think that doesn't work correctly, as it doesn't care about "<title>". =20
The attached patch should work better.

Regards
 Daniel

=2D-=20
http://www.danielnaber.de

--Boundary-00=_2Ddh98ubKAjvvnv
Content-Type: text/x-diff;
  charset="us-ascii";
  name="title_highlight.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="title_highlight.diff"

Index: search.pl
===================================================================
RCS file: /home/cvsroot/search/search.pl,v
retrieving revision 1.79
diff -u -r1.79 search.pl
--- search.pl   23 Aug 2002 11:55:19 -0000      1.79
+++ search.pl   16 Sep 2002 12:36:56 -0000
@@ -203,16 +203,22 @@
   my $color = shift;
   my $content_new = "";
   my @comments = split(/(<!--.*?-->)/igs, $content);
+  my $in_ignore = 0;
   foreach my $c (@comments) {
     my @tags = split(/(<.*?>)/igs, $c);
     foreach my $part (@tags) {
-      if( $part !~ m/^</ ) {
+      if( $part !~ m/^</ && ! $in_ignore ) {
         $part = normalize_special_chars($part);
         $part =~ s/\b($term)\b/<highlight>$1<\/highlight>/igs;
         # repair possibly damaged entities:
         $part =~ s/(&\w*)<b>$term<\/b>(\w*;)/$1$term$2/igs;
         # now really highlight:
         $part =~ s/<highlight>($term)<\/highlight>/<span style="color:black;background:$color">$1<\/span>/igs;
+      }
+      if( $part =~ /<title/i ) {
+        $in_ignore = 1;
+      } else {
+        $in_ignore = 0;
       }
       $content_new .= $part;
     }

--Boundary-00=_2Ddh98ubKAjvvnv--