git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv3 2/4] gitweb: Highlight matched part of project name when searching projects

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 27, 2012, 01:55 UTC
Message-ID
<1330307722-25351-3-git-send-email-jnareb@gmail.com>
In-Reply-To
<1330307722-25351-1-git-send-email-jnareb@gmail.com>

Use esc_html_match_hl() introduced in previous commit to escape HTML and mark match, using span element with 'match' class. Currently only the 'path' part (i.e. the project name) is highlighted; match might be on the project description. Highlighting match in description is left for next commit.

The code makes use of the fact that defined $search_regexp means that there was search going on.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Changes from v2:
* Introducing esc_html_match_hl() had been put together with
  introduction of esc_html_hl_regions() in previuos commit.
  Commit message got updated accordingly.
Changes from v1:
* Main part of esc_html_match_hl() got split into esc_html_hl_regions(),
  which was introduced in previous commit.
 gitweb/gitweb.perl |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index b790f67..829526f 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5407,7 +5407,9 @@ sub git_project_list_rows {
 			print "</td>\n";
 		}
 		print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
-		                        -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
+		                        -class => "list"},
+		                       esc_html_match_hl($pr->{'path'}, $search_regexp)) .
+		      "</td>\n" .
 		      "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
 		                        -class => "list", -title => $pr->{'descr_long'}},
 		                        esc_html($pr->{'descr'})) . "</td>\n" .
-- 
1.7.9
Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 5 in “[PATCHv3 0/4] gitweb: Match highlighting in project search”
  1. Jakub NarebskiFeb 27, 2012
  2. 1/4 gitweb: Introduce esc_html_match_hl and esc_html_hl_regionsJakub Narebski, Feb 27, 2012
  3. 2/4 gitweb: Highlight matched part of project name when searching projectsJakub Narebski, Feb 27, 2012
  4. 3/4 gitweb: Highlight matched part of project description when searching projectsJakub Narebski, Feb 27, 2012
  5. 4/4 gitweb: Highlight matched part of shortened project descriptionJakub Narebski, Feb 27, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.