浏览代码

[enh] better highlighting

Adam Tauber 11 年前
父节点
当前提交
5d9d04a16e
共有 4 个文件被更改,包括 14 次插入3 次删除
  1. 2
    0
      searx/static/css/style.css
  2. 2
    1
      searx/static/less/definitions.less
  3. 8
    0
      searx/static/less/style.less
  4. 2
    2
      searx/utils.py

+ 2
- 0
searx/static/css/style.css 查看文件

@@ -48,6 +48,8 @@ a{text-decoration:none;color:#1a11be}a:visited{color:#8e44ad}
48 48
 .right{float:right}
49 49
 .invisible{display:none}
50 50
 .left{float:left}
51
+.highlight{color:#094089}
52
+.content .highlight{color:#000}
51 53
 .image_result{float:left;margin:10px 10px;position:relative;height:160px}.image_result img{border:0;height:160px}
52 54
 .image_result p{margin:0;padding:0}.image_result p span a{display:none;color:#fff}
53 55
 .image_result p:hover span a{display:block;position:absolute;bottom:0;right:0;padding:4px;background-color:rgba(0,0,0,0.6);font-size:.7em}

+ 2
- 1
searx/static/less/definitions.less 查看文件

@@ -9,7 +9,8 @@
9 9
 @color-base: #3498DB;
10 10
 @color-base-dark: #2980B9;
11 11
 @color-base-light: #ECF0F1;
12
-
12
+@color-highlight: #094089;
13
+@color-black: #000000;
13 14
 
14 15
 /// General
15 16
 

+ 8
- 0
searx/static/less/style.less 查看文件

@@ -273,6 +273,14 @@ a {
273 273
 	float: left;
274 274
 }
275 275
 
276
+.highlight {
277
+    color: @color-highlight;
278
+}
279
+
280
+.content .highlight {
281
+    color: @color-black;
282
+}
283
+
276 284
 .image_result {
277 285
 	float: left;
278 286
 	margin: 10px 10px;

+ 2
- 2
searx/utils.py 查看文件

@@ -28,7 +28,7 @@ def highlight_content(content, query):
28 28
     query = query.decode('utf-8')
29 29
     if content.lower().find(query.lower()) > -1:
30 30
         query_regex = u'({0})'.format(re.escape(query))
31
-        content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I | re.U)
31
+        content = re.sub(query_regex, '<span class="highlight">\\1</span>', content, flags=re.I | re.U)
32 32
     else:
33 33
         regex_parts = []
34 34
         for chunk in query.split():
@@ -37,7 +37,7 @@ def highlight_content(content, query):
37 37
             else:
38 38
                 regex_parts.append(u'{0}'.format(re.escape(chunk)))
39 39
         query_regex = u'({0})'.format('|'.join(regex_parts))
40
-        content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I | re.U)
40
+        content = re.sub(query_regex, '<span class="highlight">\\1</span>', content, flags=re.I | re.U)
41 41
 
42 42
     return content
43 43