Re: Re:Highlight Matches ... Title Sometimes Got Highlighted Also - Bugs?

Daniel Naber <[email protected]>
Newsgroups gmane.comp.web.perlfect-search
Message-ID <[email protected]>
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>".  
The attached patch should work better.

Regards
 Daniel

-- 
http://www.danielnaber.de
title_highlight.diff (text/x-diff, 1.1 KB)
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;
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.