Fix regex for bolding search terms (#865)

Updated regex to not remove chinese letters in bolding regex
main
Abir10101 2022-10-26 16:23:39 +00:00 committed by GitHub
parent e99db8db26
commit 75682de892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -63,7 +63,7 @@ def bold_search_terms(response: str, query: str) -> BeautifulSoup:
if len(element) == len(target_word): if len(element) == len(target_word):
return return
if not re.match('.*[a-zA-Z0-9].*', target_word) or ( if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (
element.parent and element.parent.name == 'style'): element.parent and element.parent.name == 'style'):
return return
@ -76,7 +76,7 @@ def bold_search_terms(response: str, query: str) -> BeautifulSoup:
# Split all words out of query, grouping the ones wrapped in quotes # Split all words out of query, grouping the ones wrapped in quotes
for word in re.split(r'\s+(?=[^"]*(?:"[^"]*"[^"]*)*$)', query): for word in re.split(r'\s+(?=[^"]*(?:"[^"]*"[^"]*)*$)', query):
word = re.sub(r'[^A-Za-z0-9 ]+', '', word) word = re.sub(r'[@_!#$%^&*()<>?/\|}{~:]+', '', word)
target = response.find_all( target = response.find_all(
text=re.compile(r'' + re.escape(word), re.I)) text=re.compile(r'' + re.escape(word), re.I))
for nav_str in target: for nav_str in target: