##// END OF EJS Templates
bugfix: last line in file content highlighter was being skipped
dan -
r112:f64345db default
parent child Browse files
Show More
@@ -1,101 +1,101 b''
1 <%def name="highlight_text_file(terms, text, url, line_context=3,
1 <%def name="highlight_text_file(terms, text, url, line_context=3,
2 max_lines=10,
2 max_lines=10,
3 mimetype=None, filepath=None)">
3 mimetype=None, filepath=None)">
4 <%
4 <%
5 lines = text.split('\n')
5 lines = text.split('\n')
6 lines_of_interest = set()
6 lines_of_interest = set()
7 matching_lines = h.get_matching_line_offsets(lines, terms)
7 matching_lines = h.get_matching_line_offsets(lines, terms)
8 shown_matching_lines = 0
8 shown_matching_lines = 0
9
9
10 for line_number in matching_lines:
10 for line_number in matching_lines:
11 if len(lines_of_interest) < max_lines:
11 if len(lines_of_interest) < max_lines:
12 lines_of_interest |= set(range(
12 lines_of_interest |= set(range(
13 max(line_number - line_context, 0),
13 max(line_number - line_context, 0),
14 min(line_number + line_context, len(lines))))
14 min(line_number + line_context, len(lines) + 1)))
15 shown_matching_lines += 1
15 shown_matching_lines += 1
16
16
17 %>
17 %>
18 ${h.code_highlight(
18 ${h.code_highlight(
19 text,
19 text,
20 h.get_lexer_safe(
20 h.get_lexer_safe(
21 mimetype=mimetype,
21 mimetype=mimetype,
22 filepath=filepath,
22 filepath=filepath,
23 ),
23 ),
24 h.SearchContentCodeHtmlFormatter(
24 h.SearchContentCodeHtmlFormatter(
25 linenos=True,
25 linenos=True,
26 cssclass="code-highlight",
26 cssclass="code-highlight",
27 url=url,
27 url=url,
28 query_terms=terms,
28 query_terms=terms,
29 only_line_numbers=lines_of_interest
29 only_line_numbers=lines_of_interest
30 ))|n}
30 ))|n}
31 %if len(matching_lines) > shown_matching_lines:
31 %if len(matching_lines) > shown_matching_lines:
32 <a href="${url}">
32 <a href="${url}">
33 ${len(matching_lines) - shown_matching_lines} ${_('more matches in this file')}
33 ${len(matching_lines) - shown_matching_lines} ${_('more matches in this file')}
34 </p>
34 </p>
35 %endif
35 %endif
36 </%def>
36 </%def>
37
37
38 <div class="search-results">
38 <div class="search-results">
39 %for entry in c.formatted_results:
39 %for entry in c.formatted_results:
40 ## search results are additionally filtered, and this check is just a safe gate
40 ## search results are additionally filtered, and this check is just a safe gate
41 % if h.HasRepoPermissionAny('repository.write','repository.read','repository.admin')(entry['repository'], 'search results content check'):
41 % if h.HasRepoPermissionAny('repository.write','repository.read','repository.admin')(entry['repository'], 'search results content check'):
42 <div id="codeblock" class="codeblock">
42 <div id="codeblock" class="codeblock">
43 <div class="codeblock-header">
43 <div class="codeblock-header">
44 <h2>
44 <h2>
45 %if h.get_repo_type_by_name(entry.get('repository')) == 'hg':
45 %if h.get_repo_type_by_name(entry.get('repository')) == 'hg':
46 <i class="icon-hg"></i>
46 <i class="icon-hg"></i>
47 %elif h.get_repo_type_by_name(entry.get('repository')) == 'git':
47 %elif h.get_repo_type_by_name(entry.get('repository')) == 'git':
48 <i class="icon-git"></i>
48 <i class="icon-git"></i>
49 %elif h.get_repo_type_by_name(entry.get('repository')) == 'svn':
49 %elif h.get_repo_type_by_name(entry.get('repository')) == 'svn':
50 <i class="icon-svn"></i>
50 <i class="icon-svn"></i>
51 %endif
51 %endif
52 ${h.link_to(entry['repository'], h.url('summary_home',repo_name=entry['repository']))}
52 ${h.link_to(entry['repository'], h.url('summary_home',repo_name=entry['repository']))}
53 </h2>
53 </h2>
54 <div class="stats">
54 <div class="stats">
55 ${h.link_to(h.literal(entry['f_path']), h.url('files_home',repo_name=entry['repository'],revision=entry.get('commit_id', 'tip'),f_path=entry['f_path']))}
55 ${h.link_to(h.literal(entry['f_path']), h.url('files_home',repo_name=entry['repository'],revision=entry.get('commit_id', 'tip'),f_path=entry['f_path']))}
56 %if entry.get('lines'):
56 %if entry.get('lines'):
57 | ${entry.get('lines', 0.)} ${ungettext('line', 'lines', entry.get('lines', 0.))}
57 | ${entry.get('lines', 0.)} ${ungettext('line', 'lines', entry.get('lines', 0.))}
58 %endif
58 %endif
59 %if entry.get('size'):
59 %if entry.get('size'):
60 | ${h.format_byte_size_binary(entry['size'])}
60 | ${h.format_byte_size_binary(entry['size'])}
61 %endif
61 %endif
62 %if entry.get('mimetype'):
62 %if entry.get('mimetype'):
63 | ${entry.get('mimetype', "unknown mimetype")}
63 | ${entry.get('mimetype', "unknown mimetype")}
64 %endif
64 %endif
65 </div>
65 </div>
66 <div class="buttons">
66 <div class="buttons">
67 <a id="file_history_overview_full" href="${h.url('changelog_file_home',repo_name=entry.get('repository',''),revision=entry.get('commit_id', 'tip'),f_path=entry.get('f_path',''))}">
67 <a id="file_history_overview_full" href="${h.url('changelog_file_home',repo_name=entry.get('repository',''),revision=entry.get('commit_id', 'tip'),f_path=entry.get('f_path',''))}">
68 ${_('Show Full History')}
68 ${_('Show Full History')}
69 </a> |
69 </a> |
70 ${h.link_to(_('Annotation'), h.url('files_annotate_home', repo_name=entry.get('repository',''),revision=entry.get('commit_id', 'tip'),f_path=entry.get('f_path','')))}
70 ${h.link_to(_('Annotation'), h.url('files_annotate_home', repo_name=entry.get('repository',''),revision=entry.get('commit_id', 'tip'),f_path=entry.get('f_path','')))}
71 | ${h.link_to(_('Raw'), h.url('files_raw_home', repo_name=entry.get('repository',''),revision=entry.get('commit_id', 'tip'),f_path=entry.get('f_path','')))}
71 | ${h.link_to(_('Raw'), h.url('files_raw_home', repo_name=entry.get('repository',''),revision=entry.get('commit_id', 'tip'),f_path=entry.get('f_path','')))}
72 | <a href="${h.url('files_rawfile_home',repo_name=entry.get('repository',''),revision=entry.get('commit_id', 'tip'),f_path=entry.get('f_path',''))}">
72 | <a href="${h.url('files_rawfile_home',repo_name=entry.get('repository',''),revision=entry.get('commit_id', 'tip'),f_path=entry.get('f_path',''))}">
73 ${_('Download')}
73 ${_('Download')}
74 </a>
74 </a>
75 </div>
75 </div>
76 </div>
76 </div>
77 <div class="code-body search-code-body">
77 <div class="code-body search-code-body">
78 ${highlight_text_file(c.cur_query, entry['content'],
78 ${highlight_text_file(c.cur_query, entry['content'],
79 url=h.url('files_home',repo_name=entry['repository'],revision=entry.get('commit_id', 'tip'),f_path=entry['f_path']),
79 url=h.url('files_home',repo_name=entry['repository'],revision=entry.get('commit_id', 'tip'),f_path=entry['f_path']),
80 mimetype=entry.get('mimetype'), filepath=entry.get('path'))}
80 mimetype=entry.get('mimetype'), filepath=entry.get('path'))}
81 </div>
81 </div>
82 </div>
82 </div>
83 % endif
83 % endif
84 %endfor
84 %endfor
85 </div>
85 </div>
86 %if c.cur_query and c.formatted_results:
86 %if c.cur_query and c.formatted_results:
87 <div class="pagination-wh pagination-left" >
87 <div class="pagination-wh pagination-left" >
88 ${c.formatted_results.pager('$link_previous ~2~ $link_next')}
88 ${c.formatted_results.pager('$link_previous ~2~ $link_next')}
89 </div>
89 </div>
90 %endif
90 %endif
91
91
92 %if c.cur_query:
92 %if c.cur_query:
93 <script type="text/javascript">
93 <script type="text/javascript">
94 $(function(){
94 $(function(){
95 $(".code").mark(
95 $(".code").mark(
96 '${' '.join(h.normalize_text_for_matching(c.cur_query).split())}',
96 '${' '.join(h.normalize_text_for_matching(c.cur_query).split())}',
97 {"className": 'match',
97 {"className": 'match',
98 });
98 });
99 })
99 })
100 </script>
100 </script>
101 %endif No newline at end of file
101 %endif
General Comments 0
You need to be logged in to leave comments. Login now