Commit 2daed981 authored by Fabien Morin's avatar Fabien Morin

* use a regular expression to highligh even if ignore_case is used

* use nowrap css style to have a better displaying with long lines 
* sort results 


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23823 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5297519a
...@@ -46,7 +46,8 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1): ...@@ -46,7 +46,8 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1):
if int(i) : if int(i) :
re_flags = re.IGNORECASE re_flags = re.IGNORECASE
result = [] result = []
traverse(self, re.compile(pattern, re_flags), result, command_line_arguments) rx = re.compile(pattern, re_flags)
traverse(self, rx, result, command_line_arguments)
doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
html = '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">' html = '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'
...@@ -56,6 +57,8 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1): ...@@ -56,6 +57,8 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1):
body{ body{
background-color: #F9F9F9; background-color: #F9F9F9;
font-family: Verdana,Tahoma,Georgia,Geneva,Arial,Sans,sans-serif; font-family: Verdana,Tahoma,Georgia,Geneva,Arial,Sans,sans-serif;
font-size: 90%;
white-space:nowrap;
} }
img{ img{
border:0; border:0;
...@@ -66,13 +69,14 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1): ...@@ -66,13 +69,14 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1):
</style> </style>
</head>''' </head>'''
html_element_list = [doctype, html, head, '<body>' '<p>'] html_element_list = [doctype, html, head, '<body>' '<p>']
result_list = []
for url, path, line in result: for url, path, line in result:
path = cgi.escape(path) path = cgi.escape(path)
line = cgi.escape(line) line = cgi.escape(line)
if highlight: if highlight:
line = line.replace(pattern, '<span class="highlight">%s</span>' % pattern) line = rx.sub('<span class="highlight">\g<0></span>', line)
if ExternalEditor is None: if ExternalEditor is None:
html_element_list.append( result_list.append(
'<a href="%s/manage_workspace">%s</a>: %s<br/>' % '<a href="%s/manage_workspace">%s</a>: %s<br/>' %
(url, path, line.replace('\n', '<br/>'))) (url, path, line.replace('\n', '<br/>')))
else: else:
...@@ -80,12 +84,14 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1): ...@@ -80,12 +84,14 @@ def grep(self, pattern, A=0, B=0, r=1, i=0, highlight=1):
path_element_list = url.split('/') path_element_list = url.split('/')
external_editor_link = '%s/externalEdit_/%s' % ( external_editor_link = '%s/externalEdit_/%s' % (
'/'.join(path_element_list[:-1]), path_element_list[-1]) '/'.join(path_element_list[:-1]), path_element_list[-1])
html_element_list.append( result_list.append(
'<a href="%s/manage_workspace">%s</a>&nbsp;<a href="%s">' '<a href="%s/manage_workspace">%s</a>&nbsp;<a href="%s">'
'<img src="misc_/ExternalEditor/edit_icon" '\ '<img src="misc_/ExternalEditor/edit_icon" '\
'alt="externalEditor Icon"/></a> %s<br/>' 'alt="externalEditor Icon"/></a> %s<br/>'
% (url, path, external_editor_link, line.replace('\n', '<br/>'))) % (url, path, external_editor_link, line.replace('\n', '<br/>')))
result_list.sort()
html_element_list.extend(result_list)
html_element_list.extend(['</p>', '</body>', '</html>']) html_element_list.extend(['</p>', '</body>', '</html>'])
self.REQUEST.RESPONSE.setHeader('Content-Type', 'text/html') self.REQUEST.RESPONSE.setHeader('Content-Type', 'text/html')
return '\n'.join(html_element_list) return '\n'.join(html_element_list)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment