mirror of
https://github.com/searxng/searxng.git
synced 2025-07-14 16:59:21 +02:00
[enh] better highlighting
This commit is contained in:
parent
58de2801ce
commit
5d9d04a16e
4 changed files with 14 additions and 3 deletions
|
@ -28,7 +28,7 @@ def highlight_content(content, query):
|
|||
query = query.decode('utf-8')
|
||||
if content.lower().find(query.lower()) > -1:
|
||||
query_regex = u'({0})'.format(re.escape(query))
|
||||
content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I | re.U)
|
||||
content = re.sub(query_regex, '<span class="highlight">\\1</span>', content, flags=re.I | re.U)
|
||||
else:
|
||||
regex_parts = []
|
||||
for chunk in query.split():
|
||||
|
@ -37,7 +37,7 @@ def highlight_content(content, query):
|
|||
else:
|
||||
regex_parts.append(u'{0}'.format(re.escape(chunk)))
|
||||
query_regex = u'({0})'.format('|'.join(regex_parts))
|
||||
content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I | re.U)
|
||||
content = re.sub(query_regex, '<span class="highlight">\\1</span>', content, flags=re.I | re.U)
|
||||
|
||||
return content
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue