Преглед на файлове

[enh] add result_templates/code.html

Thomas Pointhuber преди 10 години
родител
ревизия
7adb17452d

+ 1
- 0
requirements.txt Целия файл

@@ -3,4 +3,5 @@ flask-babel
3 3
 requests
4 4
 lxml
5 5
 pyyaml
6
+pygments
6 7
 python-dateutil

+ 20
- 12
searx/engines/searchcode_code.py Целия файл

@@ -21,6 +21,18 @@ paging = True
21 21
 url = 'https://searchcode.com/'
22 22
 search_url = url+'api/codesearch_I/?{query}&p={pageno}'
23 23
 
24
+code_endings = {'c': 'c',
25
+                'css': 'css',
26
+                'cpp': 'cpp',
27
+                'c++': 'cpp',
28
+                'h': 'c',
29
+                'html': 'html',
30
+                'hpp': 'cpp',
31
+                'js': 'js',
32
+                'lua': 'lua',
33
+                'php': 'php',
34
+                'py': 'python'}
35
+
24 36
 
25 37
 # do search-request
26 38
 def request(query, params):
@@ -40,26 +52,22 @@ def response(resp):
40 52
     for result in search_results['results']:
41 53
         href = result['url']
42 54
         title = "" + result['name'] + " - " + result['filename']
43
-        content = result['repo'] + "<br />"
55
+        repo = result['repo']
44 56
         
45 57
         lines = dict()
46 58
         for line, code in result['lines'].items():
47 59
             lines[int(line)] = code
48 60
 
49
-        content = content + '<pre class="code-formatter"><table class="code">'
50
-        for line, code in sorted(lines.items()):
51
-            content = content + '<tr><td class="line-number" style="padding-right:5px;">' 
52
-            content = content + str(line) + '</td><td class="code-snippet">' 
53
-            # Replace every two spaces with ' &nbps;' to keep formatting while allowing the browser to break the line if necessary
54
-            content = content + cgi.escape(code).replace('\t', '    ').replace('  ', '&nbsp; ').replace('  ', ' &nbsp;') 
55
-            content = content + "</td></tr>"
56
-            
57
-        content = content + "</table></pre>"
58
-        
61
+        code_language = code_endings.get(result['filename'].split('.')[-1].lower(), None)
62
+
59 63
         # append result
60 64
         results.append({'url': href,
61 65
                         'title': title,
62
-                        'content': content})
66
+                        'content': '',
67
+                        'repository': repo,
68
+                        'codelines': sorted(lines.items()),
69
+                        'code_language': code_language,
70
+                        'template': 'code.html'})
63 71
 
64 72
     # return results
65 73
     return results

+ 79
- 1
searx/static/courgette/css/style.css Целия файл

@@ -579,4 +579,82 @@ select {
579 579
   border: 1px solid #DDD;
580 580
   padding: 0.5em 0.8em;
581 581
   font-size: 1em;
582
-}
582
+}
583
+
584
+.highlight .hll { background-color: #ffffcc }
585
+.highlight  { background: #f8f8f8; }
586
+.highlight .c { color: #408080; font-style: italic } /* Comment */
587
+.highlight .err { border: 1px solid #FF0000 } /* Error */
588
+.highlight .k { color: #008000; font-weight: bold } /* Keyword */
589
+.highlight .o { color: #666666 } /* Operator */
590
+.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
591
+.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
592
+.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
593
+.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
594
+.highlight .gd { color: #A00000 } /* Generic.Deleted */
595
+.highlight .ge { font-style: italic } /* Generic.Emph */
596
+.highlight .gr { color: #FF0000 } /* Generic.Error */
597
+.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
598
+.highlight .gi { color: #00A000 } /* Generic.Inserted */
599
+.highlight .go { color: #888888 } /* Generic.Output */
600
+.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
601
+.highlight .gs { font-weight: bold } /* Generic.Strong */
602
+.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
603
+.highlight .gt { color: #0044DD } /* Generic.Traceback */
604
+.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
605
+.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
606
+.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
607
+.highlight .kp { color: #008000 } /* Keyword.Pseudo */
608
+.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
609
+.highlight .kt { color: #B00040 } /* Keyword.Type */
610
+.highlight .m { color: #666666 } /* Literal.Number */
611
+.highlight .s { color: #BA2121 } /* Literal.String */
612
+.highlight .na { color: #7D9029 } /* Name.Attribute */
613
+.highlight .nb { color: #008000 } /* Name.Builtin */
614
+.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
615
+.highlight .no { color: #880000 } /* Name.Constant */
616
+.highlight .nd { color: #AA22FF } /* Name.Decorator */
617
+.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
618
+.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
619
+.highlight .nf { color: #0000FF } /* Name.Function */
620
+.highlight .nl { color: #A0A000 } /* Name.Label */
621
+.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
622
+.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
623
+.highlight .nv { color: #19177C } /* Name.Variable */
624
+.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
625
+.highlight .w { color: #bbbbbb } /* Text.Whitespace */
626
+.highlight .mf { color: #666666 } /* Literal.Number.Float */
627
+.highlight .mh { color: #666666 } /* Literal.Number.Hex */
628
+.highlight .mi { color: #666666 } /* Literal.Number.Integer */
629
+.highlight .mo { color: #666666 } /* Literal.Number.Oct */
630
+.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
631
+.highlight .sc { color: #BA2121 } /* Literal.String.Char */
632
+.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
633
+.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
634
+.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
635
+.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
636
+.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
637
+.highlight .sx { color: #008000 } /* Literal.String.Other */
638
+.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
639
+.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
640
+.highlight .ss { color: #19177C } /* Literal.String.Symbol */
641
+.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
642
+.highlight .vc { color: #19177C } /* Name.Variable.Class */
643
+.highlight .vg { color: #19177C } /* Name.Variable.Global */
644
+.highlight .vi { color: #19177C } /* Name.Variable.Instance */
645
+.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
646
+
647
+.highlight pre { overflow: auto; }
648
+
649
+.highlight .lineno {
650
+    -webkit-touch-callout: none;
651
+    -webkit-user-select: none;
652
+    -khtml-user-select: none;
653
+    -moz-user-select: none;
654
+    -ms-user-select: none;
655
+    user-select: none;
656
+    cursor: default;
657
+}
658
+    
659
+.highlight .lineno::selection { background: transparent; } /* WebKit/Blink Browsers */
660
+.highlight .lineno::-moz-selection { background: transparent; } /* Gecko Browsers */

+ 1
- 86
searx/static/default/css/style.css
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 83
- 0
searx/static/default/less/code.less Целия файл

@@ -0,0 +1,83 @@
1
+.highlight .hll { background-color: #ffffcc }
2
+.highlight  { background: #f8f8f8; }
3
+.highlight .c { color: #408080; font-style: italic } /* Comment */
4
+.highlight .err { border: 1px solid #FF0000 } /* Error */
5
+.highlight .k { color: #008000; font-weight: bold } /* Keyword */
6
+.highlight .o { color: #666666 } /* Operator */
7
+.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
8
+.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
9
+.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
10
+.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
11
+.highlight .gd { color: #A00000 } /* Generic.Deleted */
12
+.highlight .ge { font-style: italic } /* Generic.Emph */
13
+.highlight .gr { color: #FF0000 } /* Generic.Error */
14
+.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
15
+.highlight .gi { color: #00A000 } /* Generic.Inserted */
16
+.highlight .go { color: #888888 } /* Generic.Output */
17
+.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
18
+.highlight .gs { font-weight: bold } /* Generic.Strong */
19
+.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
20
+.highlight .gt { color: #0044DD } /* Generic.Traceback */
21
+.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
22
+.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
23
+.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
24
+.highlight .kp { color: #008000 } /* Keyword.Pseudo */
25
+.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
26
+.highlight .kt { color: #B00040 } /* Keyword.Type */
27
+.highlight .m { color: #666666 } /* Literal.Number */
28
+.highlight .s { color: #BA2121 } /* Literal.String */
29
+.highlight .na { color: #7D9029 } /* Name.Attribute */
30
+.highlight .nb { color: #008000 } /* Name.Builtin */
31
+.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
32
+.highlight .no { color: #880000 } /* Name.Constant */
33
+.highlight .nd { color: #AA22FF } /* Name.Decorator */
34
+.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
35
+.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
36
+.highlight .nf { color: #0000FF } /* Name.Function */
37
+.highlight .nl { color: #A0A000 } /* Name.Label */
38
+.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
39
+.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
40
+.highlight .nv { color: #19177C } /* Name.Variable */
41
+.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
42
+.highlight .w { color: #bbbbbb } /* Text.Whitespace */
43
+.highlight .mf { color: #666666 } /* Literal.Number.Float */
44
+.highlight .mh { color: #666666 } /* Literal.Number.Hex */
45
+.highlight .mi { color: #666666 } /* Literal.Number.Integer */
46
+.highlight .mo { color: #666666 } /* Literal.Number.Oct */
47
+.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
48
+.highlight .sc { color: #BA2121 } /* Literal.String.Char */
49
+.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
50
+.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
51
+.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
52
+.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
53
+.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
54
+.highlight .sx { color: #008000 } /* Literal.String.Other */
55
+.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
56
+.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
57
+.highlight .ss { color: #19177C } /* Literal.String.Symbol */
58
+.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
59
+.highlight .vc { color: #19177C } /* Name.Variable.Class */
60
+.highlight .vg { color: #19177C } /* Name.Variable.Global */
61
+.highlight .vi { color: #19177C } /* Name.Variable.Instance */
62
+.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
63
+
64
+.highlight pre {
65
+    overflow: auto;
66
+}
67
+
68
+.highlight .lineno {
69
+    -webkit-touch-callout: none;
70
+    -webkit-user-select: none;
71
+    -khtml-user-select: none;
72
+    -moz-user-select: none;
73
+    -ms-user-select: none;
74
+    user-select: none;
75
+    cursor: default;
76
+    
77
+    &::selection {
78
+        background: transparent; /* WebKit/Blink Browsers */
79
+    }
80
+    &::-moz-selection {
81
+        background: transparent; /* Gecko Browsers */
82
+    }
83
+}

+ 2
- 0
searx/static/default/less/style.less Целия файл

@@ -8,6 +8,8 @@
8 8
 
9 9
 @import "mixins.less";
10 10
 
11
+@import "code.less";
12
+
11 13
 // Main LESS-Code
12 14
 
13 15
 html {

+ 1
- 915
searx/static/oscar/css/bootstrap.min.css
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 1
- 22
searx/static/oscar/css/oscar.min.css Целия файл

@@ -1,22 +1 @@
1
-html{position:relative;min-height:100%}
2
-body{margin-bottom:80px}
3
-.footer{position:absolute;bottom:0;width:100%;height:60px}
4
-input[type=checkbox]:checked~.label_hide_if_checked{display:none}
5
-input[type=checkbox]:not(:checked)~.label_hide_if_not_checked{display:none}
6
-.result_header{margin-bottom:5px;margin-top:20px}.result_header .favicon{margin-bottom:-3px}
7
-.result_header a{vertical-align:bottom}.result_header a .highlight{font-weight:bold}
8
-.result-content{margin-top:5px}.result-content .highlight{font-weight:bold}
9
-.result-default{clear:both}
10
-.result-images{float:left !important}
11
-.img-thumbnail{margin:5px;max-height:128px;min-height:128px}
12
-.result-videos{clear:both}
13
-.result-torrents{clear:both}
14
-.result-map{clear:both}
15
-.suggestion_item{margin:2px 5px}
16
-.result_download{margin-right:5px}
17
-#pagination{margin-top:30px;padding-bottom:50px}
18
-.infobox .infobox_part{margin-bottom:20px}
19
-.infobox .infobox_part:last-child{margin-bottom:0}
20
-.search_categories{margin:10px 0;text-transform:capitalize}
21
-.cursor-text{cursor:text !important}
22
-.cursor-pointer{cursor:pointer !important}
1
+html{position:relative;min-height:100%}body{margin-bottom:80px}.footer{position:absolute;bottom:0;width:100%;height:60px}input[type=checkbox]:checked~.label_hide_if_checked{display:none}input[type=checkbox]:not(:checked)~.label_hide_if_not_checked{display:none}.result_header{margin-bottom:5px;margin-top:20px}.result_header .favicon{margin-bottom:-3px}.result_header a{vertical-align:bottom}.result_header a .highlight{font-weight:bold}.result-content{margin-top:5px}.result-content .highlight{font-weight:bold}.result-default{clear:both}.result-images{float:left !important}.img-thumbnail{margin:5px;max-height:128px;min-height:128px}.result-videos{clear:both}.result-torrents{clear:both}.result-map{clear:both}.suggestion_item{margin:2px 5px}.result_download{margin-right:5px}#pagination{margin-top:30px;padding-bottom:50px}.infobox .infobox_part{margin-bottom:20px}.infobox .infobox_part:last-child{margin-bottom:0}.search_categories{margin:10px 0;text-transform:capitalize}.cursor-text{cursor:text !important}.cursor-pointer{cursor:pointer !important}.highlight .hll{background-color:#ffc}.highlight{background:#f8f8f8}.highlight .c{color:#408080;font-style:italic}.highlight .err{border:1px solid #f00}.highlight .k{color:#008000;font-weight:bold}.highlight .o{color:#666}.highlight .cm{color:#408080;font-style:italic}.highlight .cp{color:#bc7a00}.highlight .c1{color:#408080;font-style:italic}.highlight .cs{color:#408080;font-style:italic}.highlight .gd{color:#a00000}.highlight .ge{font-style:italic}.highlight .gr{color:#f00}.highlight .gh{color:#000080;font-weight:bold}.highlight .gi{color:#00a000}.highlight .go{color:#888}.highlight .gp{color:#000080;font-weight:bold}.highlight .gs{font-weight:bold}.highlight .gu{color:#800080;font-weight:bold}.highlight .gt{color:#04d}.highlight .kc{color:#008000;font-weight:bold}.highlight .kd{color:#008000;font-weight:bold}.highlight .kn{color:#008000;font-weight:bold}.highlight .kp{color:#008000}.highlight .kr{color:#008000;font-weight:bold}.highlight .kt{color:#b00040}.highlight .m{color:#666}.highlight .s{color:#ba2121}.highlight .na{color:#7d9029}.highlight .nb{color:#008000}.highlight .nc{color:#00f;font-weight:bold}.highlight .no{color:#800}.highlight .nd{color:#a2f}.highlight .ni{color:#999;font-weight:bold}.highlight .ne{color:#d2413a;font-weight:bold}.highlight .nf{color:#00f}.highlight .nl{color:#a0a000}.highlight .nn{color:#00f;font-weight:bold}.highlight .nt{color:#008000;font-weight:bold}.highlight .nv{color:#19177c}.highlight .ow{color:#a2f;font-weight:bold}.highlight .w{color:#bbb}.highlight .mf{color:#666}.highlight .mh{color:#666}.highlight .mi{color:#666}.highlight .mo{color:#666}.highlight .sb{color:#ba2121}.highlight .sc{color:#ba2121}.highlight .sd{color:#ba2121;font-style:italic}.highlight .s2{color:#ba2121}.highlight .se{color:#b62;font-weight:bold}.highlight .sh{color:#ba2121}.highlight .si{color:#b68;font-weight:bold}.highlight .sx{color:#008000}.highlight .sr{color:#b68}.highlight .s1{color:#ba2121}.highlight .ss{color:#19177c}.highlight .bp{color:#008000}.highlight .vc{color:#19177c}.highlight .vg{color:#19177c}.highlight .vi{color:#19177c}.highlight .il{color:#666}.highlight .lineno{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.highlight .lineno::selection{background:transparent}.highlight .lineno::-moz-selection{background:transparent}

+ 79
- 0
searx/static/oscar/less/oscar/code.less Целия файл

@@ -0,0 +1,79 @@
1
+.highlight .hll { background-color: #ffffcc }
2
+.highlight  { background: #f8f8f8; }
3
+.highlight .c { color: #408080; font-style: italic } /* Comment */
4
+.highlight .err { border: 1px solid #FF0000 } /* Error */
5
+.highlight .k { color: #008000; font-weight: bold } /* Keyword */
6
+.highlight .o { color: #666666 } /* Operator */
7
+.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
8
+.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
9
+.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
10
+.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
11
+.highlight .gd { color: #A00000 } /* Generic.Deleted */
12
+.highlight .ge { font-style: italic } /* Generic.Emph */
13
+.highlight .gr { color: #FF0000 } /* Generic.Error */
14
+.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
15
+.highlight .gi { color: #00A000 } /* Generic.Inserted */
16
+.highlight .go { color: #888888 } /* Generic.Output */
17
+.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
18
+.highlight .gs { font-weight: bold } /* Generic.Strong */
19
+.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
20
+.highlight .gt { color: #0044DD } /* Generic.Traceback */
21
+.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
22
+.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
23
+.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
24
+.highlight .kp { color: #008000 } /* Keyword.Pseudo */
25
+.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
26
+.highlight .kt { color: #B00040 } /* Keyword.Type */
27
+.highlight .m { color: #666666 } /* Literal.Number */
28
+.highlight .s { color: #BA2121 } /* Literal.String */
29
+.highlight .na { color: #7D9029 } /* Name.Attribute */
30
+.highlight .nb { color: #008000 } /* Name.Builtin */
31
+.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
32
+.highlight .no { color: #880000 } /* Name.Constant */
33
+.highlight .nd { color: #AA22FF } /* Name.Decorator */
34
+.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
35
+.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
36
+.highlight .nf { color: #0000FF } /* Name.Function */
37
+.highlight .nl { color: #A0A000 } /* Name.Label */
38
+.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
39
+.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
40
+.highlight .nv { color: #19177C } /* Name.Variable */
41
+.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
42
+.highlight .w { color: #bbbbbb } /* Text.Whitespace */
43
+.highlight .mf { color: #666666 } /* Literal.Number.Float */
44
+.highlight .mh { color: #666666 } /* Literal.Number.Hex */
45
+.highlight .mi { color: #666666 } /* Literal.Number.Integer */
46
+.highlight .mo { color: #666666 } /* Literal.Number.Oct */
47
+.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
48
+.highlight .sc { color: #BA2121 } /* Literal.String.Char */
49
+.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
50
+.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
51
+.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
52
+.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
53
+.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
54
+.highlight .sx { color: #008000 } /* Literal.String.Other */
55
+.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
56
+.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
57
+.highlight .ss { color: #19177C } /* Literal.String.Symbol */
58
+.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
59
+.highlight .vc { color: #19177C } /* Name.Variable.Class */
60
+.highlight .vg { color: #19177C } /* Name.Variable.Global */
61
+.highlight .vi { color: #19177C } /* Name.Variable.Instance */
62
+.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
63
+
64
+.highlight .lineno {
65
+    -webkit-touch-callout: none;
66
+    -webkit-user-select: none;
67
+    -khtml-user-select: none;
68
+    -moz-user-select: none;
69
+    -ms-user-select: none;
70
+    user-select: none;
71
+    cursor: default;
72
+    
73
+    &::selection {
74
+        background: transparent; /* WebKit/Blink Browsers */
75
+    }
76
+    &::-moz-selection {
77
+        background: transparent; /* Gecko Browsers */
78
+    }
79
+}

+ 2
- 0
searx/static/oscar/less/oscar/oscar.less Целия файл

@@ -9,3 +9,5 @@
9 9
 @import "search.less";
10 10
 
11 11
 @import "cursor.less";
12
+
13
+@import "code.less";

+ 9
- 0
searx/templates/courgette/result_templates/code.html Целия файл

@@ -0,0 +1,9 @@
1
+<div class="result {{ result.class }}">
2
+    <h3 class="result_title"> {% if result['favicon'] %}<img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}" />{% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
3
+    <p class="url">{{ result.pretty_url }} <a class="cache_link" href="https://web.archive.org/web/{{ result.url }}">cached</a></p>
4
+    {% if result.publishedDate %}<p class="published_date">{{ result.publishedDate }}</p>{% endif %}
5
+    <p class="content">{% if result.img_src %}<img src="{{ result.img_src }}" class="image" />{% endif %}{% if result.content %}{{ result.content|safe }}<br class="last"/>{% endif %}</p>
6
+    {% if result.repository %}<p class="result-content"><a href="{{ result.repository|safe }}">{{ result.repository }}</a></p>{% endif %}
7
+
8
+    {{ result.codelines|code_highlighter(result.code_language)|safe }}
9
+</div>

+ 9
- 0
searx/templates/default/result_templates/code.html Целия файл

@@ -0,0 +1,9 @@
1
+<div class="result {{ result.class }}">
2
+    <h3 class="result_title"> {% if result['favicon'] %}<img width="14" height="14" class="favicon" src="static/{{theme}}/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}" />{% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
3
+    <p class="url">{{ result.pretty_url }} <a class="cache_link" href="https://web.archive.org/web/{{ result.url }}">cached</a></p>
4
+    {% if result.publishedDate %}<p class="published_date">{{ result.publishedDate }}</p>{% endif %}
5
+    <p class="content">{% if result.img_src %}<img src="{{ result.img_src }}" class="image" />{% endif %}{% if result.content %}{{ result.content|safe }}<br class="last"/>{% endif %}</p>
6
+    {% if result.repository %}<p class="result-content"><a href="{{ result.repository|safe }}">{{ result.repository }}</a></p>{% endif %}
7
+
8
+    {{ result.codelines|code_highlighter(result.code_language)|safe }}
9
+</div>

+ 17
- 0
searx/templates/oscar/result_templates/code.html Целия файл

@@ -0,0 +1,17 @@
1
+{% from 'oscar/macros.html' import icon %}
2
+
3
+<h4 class="result_header">{% if result['favicon'] %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result['favicon'] }}.png" alt="{{ result['favicon'] }}" /> {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
4
+
5
+{% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
6
+<small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
7
+
8
+{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
9
+
10
+{% if result.repository %}<p class="result-content">{{ icon('file') }} <a href="{{ result.repository|safe }}">{{ result.repository }}</a></p>{% endif %}
11
+
12
+{{ result.codelines|code_highlighter(result.code_language)|safe }}
13
+
14
+<div class="clearfix"></div>
15
+
16
+<span class="label label-default pull-right">{{ result.engine }}</span>
17
+<p class="text-muted">{{ result.pretty_url }}</p>

+ 46
- 0
searx/webapp.py Целия файл

@@ -33,6 +33,9 @@ from flask import (
33 33
     redirect, send_from_directory
34 34
 )
35 35
 from flask.ext.babel import Babel, gettext, format_date
36
+from pygments import highlight
37
+from pygments.lexers import get_lexer_by_name
38
+from pygments.formatters import HtmlFormatter
36 39
 from searx import settings, searx_dir
37 40
 from searx.engines import (
38 41
     categories, engines, get_engines_stats, engine_shortcuts
@@ -90,6 +93,49 @@ def get_locale():
90 93
     return locale
91 94
 
92 95
 
96
+# code-highlighter
97
+@app.template_filter('code_highlighter')
98
+def code_highlighter(codelines, language=None):
99
+    if not language:
100
+        language = 'text'
101
+
102
+    # find lexer by programing language
103
+    lexer = get_lexer_by_name(language, stripall=True)
104
+    
105
+    html_code = ''
106
+    tmp_code = ''
107
+    last_line = None
108
+
109
+    # parse lines
110
+    for line, code in codelines:
111
+        if not last_line:
112
+            line_code_start = line
113
+
114
+        # new codeblock is detected
115
+        if last_line != None and\
116
+           last_line +1 != line:
117
+
118
+            # highlight last codepart
119
+            formatter = HtmlFormatter(linenos='inline', linenostart=line_code_start)
120
+            html_code = html_code + highlight(tmp_code, lexer, formatter)
121
+            
122
+            # reset conditions for next codepart
123
+            tmp_code = ''
124
+            line_code_start = line
125
+
126
+        # add codepart
127
+        tmp_code += code + '\n'
128
+        
129
+        # update line
130
+        last_line = line
131
+
132
+    # highlight last codepart
133
+    formatter = HtmlFormatter(linenos='inline', linenostart=line_code_start)
134
+    html_code = html_code + highlight(tmp_code, lexer, formatter)
135
+
136
+    return html_code
137
+
138
+
93 139
 def get_base_url():
94 140
     if settings['server']['base_url']:
95 141
         hostname = settings['server']['base_url']

+ 1
- 0
setup.py Целия файл

@@ -44,6 +44,7 @@ setup(
44 44
         'requests',
45 45
         'lxml',
46 46
         'pyyaml',
47
+        'pygments',
47 48
         'setuptools',
48 49
         'python-dateutil',
49 50
     ],

+ 1
- 0
versions.cfg Целия файл

@@ -4,6 +4,7 @@ Flask = 0.10.1
4 4
 Flask-Babel = 0.9
5 5
 Jinja2 = 2.7.2
6 6
 MarkupSafe = 0.18
7
+Pygments = 2.0.1
7 8
 WebOb = 1.3.1
8 9
 WebTest = 2.0.11
9 10
 Werkzeug = 0.9.4