Commit 9dc9995e4c70791b8dc1dca4d0492dbcb3ea184c
1 parent
46794a64
Exists in
master
and in
13 other branches
Forcing escape of text_block on highlights
Showing
1 changed file
with
7 additions
and
0 deletions
Show diff stats
src/colab/utils/highlighting.py
| 1 | 1 | from haystack.utils import Highlighter |
| 2 | 2 | from django.conf import settings |
| 3 | +from django.utils.html import escape, strip_tags | |
| 3 | 4 | |
| 4 | 5 | |
| 5 | 6 | class ColabHighlighter(Highlighter): |
| 7 | + def highlight(self, text_block): | |
| 8 | + self.text_block = escape(strip_tags(text_block)) | |
| 9 | + highlight_locations = self.find_highlightable_words() | |
| 10 | + start_offset, end_offset = self.find_window(highlight_locations) | |
| 11 | + return self.render_html(highlight_locations, start_offset, end_offset) | |
| 12 | + | |
| 6 | 13 | def find_window(self, highlight_locations): |
| 7 | 14 | """Getting the HIGHLIGHT_NUM_CHARS_BEFORE_MATCH setting |
| 8 | 15 | to find how many characters before the first word found should | ... | ... |