From fe8bfa655a824f27789bbd33ac3c61751377047d Mon Sep 17 00:00:00 2001 From: DUO Labs Date: Tue, 26 Oct 2021 17:22:52 -0400 Subject: [PATCH] Fix errors with boldening terms --- app/utils/results.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/utils/results.py b/app/utils/results.py index befc86d..7269ca7 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -53,15 +53,7 @@ def bold_search_terms(response: str, query: str) -> BeautifulSoup: # Replace all instances of the word, but maintaining the same case in # the replacement element.replace_with( - element.replace( - target_word.lower(), f'{target_word.lower()}' - ).replace( - target_word.capitalize(), f'{target_word.capitalize()}' - ).replace( - target_word.title(), f'{target_word.title()}' - ).replace( - target_word.upper(), f'{target_word.upper()}' - ) + re.sub(fr"\b({target_word})\b",r"\1",element,flags=re.I) ) # Split all words out of query, grouping the ones wrapped in quotes