From c6eb95112e7b0a7add687b609efce7eab7814f6b Mon Sep 17 00:00:00 2001 From: Kamil Date: Wed, 27 Nov 2024 17:15:35 +0000 Subject: [PATCH] adjusted highlight filter, to highlight a perfect match --- app/filters.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/filters.py b/app/filters.py index 1bc4ec7..ac8c13f 100644 --- a/app/filters.py +++ b/app/filters.py @@ -14,10 +14,17 @@ def template_filter(name): return decorator @template_filter('highlight') -def highlight_search(text, search_query): +def highlight_search(text: str, search_query: str) -> Markup: if not search_query: return text + search_query_escaped = re.escape(search_query) + + # If the text matches the search query exactly, apply a different highlight + if text.strip().lower() == search_query.strip().lower(): + return Markup(f'{text}') + + # Highlight partial matches in the text highlighted_text = re.sub( f"({search_query_escaped})", r'\1',