%def name="highlight_text_file(terms, text, url, line_context=3, max_lines=10, mimetype=None, filepath=None)"> <% lines = text.split('\n') lines_of_interest = set() matching_lines = h.get_matching_line_offsets(lines, terms) shown_matching_lines = 0 for line_number in matching_lines: if len(lines_of_interest) < max_lines: lines_of_interest |= set(range( max(line_number - line_context, 0), min(line_number + line_context, len(lines)))) shown_matching_lines += 1 %> ${h.code_highlight( text, h.get_lexer_safe( mimetype=mimetype, filepath=filepath, ), h.SearchContentCodeHtmlFormatter( linenos=True, cssclass="code-highlight", url=url, query_terms=terms, only_line_numbers=lines_of_interest ))|n} %if len(matching_lines) > shown_matching_lines: ${len(matching_lines) - shown_matching_lines} ${_('more matches in this file')}
%endif %def>