Mercurial > hatta
changeset 2448:29136df093ed
Fix #101 Properly highlight words in search results.
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 02 Apr 2014 10:31:52 +0200 |
| parents | d415e9ef5a2b |
| children | 46f0b8018ce8 |
| files | examples/slides/slides.py hatta/views.py |
| diffstat | 2 files changed, 5 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/slides/slides.py Thu Dec 05 20:01:34 2013 +0100 +++ b/examples/slides/slides.py Wed Apr 02 10:31:52 2014 +0200 @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # -*- coding: utf-8 -*- """
--- a/hatta/views.py Thu Dec 05 20:01:34 2013 +0100 +++ b/hatta/views.py Wed Apr 02 10:31:52 2014 +0200 @@ -546,6 +546,9 @@ _ = request.wiki.gettext + def highlight_html(m): + return werkzeug.html.b(m.group(0), class_="highlighted") + def search_snippet(title, words): """Extract a snippet of text for search results.""" @@ -562,8 +565,7 @@ min_pos = max(position - 60, 0) max_pos = min(position + 60, len(text)) snippet = werkzeug.escape(text[min_pos:max_pos]) - highlighted = werkzeug.html.b(match.group(0), class_="highlight") - html = regexp.sub(highlighted, snippet) + html = regexp.sub(highlight_html, snippet) return html def page_search(words, page, request):
