This commit is contained in:
allixx 2023-12-31 10:03:10 -07:00 committed by GitHub
commit 98ef5195d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -290,10 +290,8 @@ def highlight_content(content, query):
if len(qs) > 0:
queries.extend(re.findall(regex_highlight_cjk(qs), content, flags=re.I | re.U))
if len(queries) > 0:
for q in set(queries):
content = re.sub(
regex_highlight_cjk(q), f'<span class="highlight">{q}</span>'.replace('\\', r'\\'), content
)
regex = re.compile("|".join(map(regex_highlight_cjk, queries)))
return regex.sub(lambda match: f'<span class="highlight">{match.group(0)}</span>'.replace('\\', r'\\'), content)
return content

View file

@ -57,6 +57,11 @@ class TestWebUtils(SearxTestCase):
]
),
),
(
'a class',
'a string with class.',
'<span class="highlight">a</span> string with <span class="highlight">class</span>.',
),
)
for query, content, expected in data:
self.assertEqual(webutils.highlight_content(content, query), expected)