Bladeren bron

Merge branch 'code_results' of https://github.com/pointhi/searx into pointhi-code_results

Conflicts:
	searx/static/themes/default/css/style.css
	searx/static/themes/oscar/css/oscar.min.css
	searx/templates/oscar/result_templates/torrent.html
Adam Tauber 10 jaren geleden
bovenliggende
commit
a04fafd419

+ 1
- 0
requirements.txt Bestand weergeven

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

+ 15
- 13
searx/engines/searchcode_code.py Bestand weergeven

@@ -10,7 +10,7 @@
10 10
 
11 11
 from urllib import urlencode
12 12
 from json import loads
13
-import cgi
13
+
14 14
 
15 15
 # engine dependent config
16 16
 categories = ['it']
@@ -20,6 +20,11 @@ paging = True
20 20
 url = 'https://searchcode.com/'
21 21
 search_url = url+'api/codesearch_I/?{query}&p={pageno}'
22 22
 
23
+# special code-endings which are not recognised by the file ending
24
+code_endings = {'cs': 'c#',
25
+                'h': 'c',
26
+                'hpp': 'cpp'}
27
+
23 28
 
24 29
 # do search-request
25 30
 def request(query, params):
@@ -39,27 +44,24 @@ def response(resp):
39 44
     for result in search_results['results']:
40 45
         href = result['url']
41 46
         title = "" + result['name'] + " - " + result['filename']
42
-        content = result['repo'] + "<br />"
47
+        repo = result['repo']
43 48
 
44 49
         lines = dict()
45 50
         for line, code in result['lines'].items():
46 51
             lines[int(line)] = code
47 52
 
48
-        content = content + '<pre class="code-formatter"><table class="code">'
49
-        for line, code in sorted(lines.items()):
50
-            content = content + '<tr><td class="line-number" style="padding-right:5px;">'
51
-            content = content + str(line) + '</td><td class="code-snippet">'
52
-            # Replace every two spaces with ' &nbps;' to keep formatting
53
-            # 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>"
53
+        code_language = code_endings.get(
54
+            result['filename'].split('.')[-1].lower(),
55
+            result['filename'].split('.')[-1].lower())
58 56
 
59 57
         # append result
60 58
         results.append({'url': href,
61 59
                         'title': title,
62
-                        'content': content})
60
+                        'content': '',
61
+                        'repository': repo,
62
+                        'codelines': sorted(lines.items()),
63
+                        'code_language': code_language,
64
+                        'template': 'code.html'})
63 65
 
64 66
     # return results
65 67
     return results

+ 1
- 915
searx/static/css/bootstrap.min.css
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 79
- 1
searx/static/themes/courgette/css/style.css Bestand weergeven

@@ -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
- 1
searx/static/themes/default/css/style.css
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 83
- 0
searx/static/themes/default/less/code.less Bestand weergeven

@@ -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/themes/default/less/style.less Bestand weergeven

@@ -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
- 26
searx/static/themes/oscar/css/oscar.min.css Bestand weergeven

@@ -1,26 +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,input[type=checkbox]:checked+.label_hide_if_not_checked+.label_hide_if_checked{display:none}
5
-input[type=checkbox]:not(:checked)+.label_hide_if_not_checked,input[type=checkbox]:not(:checked)+.label_hide_if_checked+.label_hide_if_not_checked{display:none}
6
-.result_header{margin-bottom:5px;margin-top:20px}
7
-.result_header .favicon{margin-bottom:-3px}
8
-.result_header a{vertical-align:bottom}
9
-.result_header a .highlight{font-weight:bold}
10
-.result-content{margin-top:5px}
11
-.result-content .highlight{font-weight:bold}
12
-.result-default{clear:both}
13
-.result-images{float:left !important}
14
-.img-thumbnail{margin:5px;max-height:128px;min-height:128px}
15
-.result-videos{clear:both}
16
-.result-torrents{clear:both}
17
-.result-map{clear:both}
18
-.suggestion_item{margin:2px 5px}
19
-.result_download{margin-right:5px}
20
-#pagination{margin-top:30px;padding-bottom:50px}
21
-.infobox .infobox_part{margin-bottom:20px}
22
-.infobox .infobox_part:last-child{margin-bottom:0}
23
-.search_categories{margin:10px 0;text-transform:capitalize}
24
-.cursor-text{cursor:text !important}
25
-.cursor-pointer{cursor:pointer !important}
26
-
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:700}.result-content{margin-top:5px}.result-content .highlight{font-weight:700}.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}.result-code{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 red}.highlight .k{color:green;font-weight:700}.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:red}.highlight .gh{color:navy;font-weight:700}.highlight .gi{color:#00a000}.highlight .go{color:#888}.highlight .gp{color:navy;font-weight:700}.highlight .gs{font-weight:700}.highlight .gu{color:purple;font-weight:700}.highlight .gt{color:#04d}.highlight .kc{color:green;font-weight:700}.highlight .kd{color:green;font-weight:700}.highlight .kn{color:green;font-weight:700}.highlight .kp{color:green}.highlight .kr{color:green;font-weight:700}.highlight .kt{color:#b00040}.highlight .m{color:#666}.highlight .s{color:#ba2121}.highlight .na{color:#7d9029}.highlight .nb{color:green}.highlight .nc{color:#00F;font-weight:700}.highlight .no{color:#800}.highlight .nd{color:#a2f}.highlight .ni{color:#999;font-weight:700}.highlight .ne{color:#D2413A;font-weight:700}.highlight .nf{color:#00f}.highlight .nl{color:#a0a000}.highlight .nn{color:#00F;font-weight:700}.highlight .nt{color:green;font-weight:700}.highlight .nv{color:#19177c}.highlight .ow{color:#A2F;font-weight:700}.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:700}.highlight .sh{color:#ba2121}.highlight .si{color:#B68;font-weight:700}.highlight .sx{color:green}.highlight .sr{color:#b68}.highlight .s1{color:#ba2121}.highlight .ss{color:#19177c}.highlight .bp{color:green}.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:0 0}.highlight .lineno::-moz-selection{background:0 0}

+ 40
- 3
searx/static/themes/oscar/gruntfile.js Bestand weergeven

@@ -33,9 +33,43 @@ module.exports = function(grunt) {
33 33
         }
34 34
       }
35 35
     },
36
+    less: {
37
+        development: {
38
+            options: {
39
+                paths: ["less/oscar"]
40
+                //banner: '/*! less/oscar/oscar.css | <%= grunt.template.today("dd-mm-yyyy") %> | https://github.com/asciimoo/searx */\n'
41
+            },
42
+            files: {"css/oscar.css": "less/oscar/oscar.less"}
43
+        },
44
+        production: {
45
+            options: {
46
+                paths: ["less/oscar"],
47
+                //banner: '/*! less/oscar/oscar.css | <%= grunt.template.today("dd-mm-yyyy") %> | https://github.com/asciimoo/searx */\n',
48
+                cleancss: true
49
+            },
50
+            files: {"css/oscar.min.css": "less/oscar/oscar.less"}
51
+        },
52
+        bootstrap: {
53
+            options: {
54
+                paths: ["less/bootstrap"],
55
+                cleancss: true
56
+            },
57
+            files: {"css/bootstrap.min.css": "less/bootstrap/bootstrap.less"}
58
+        },
59
+    },
36 60
     watch: {
37
-      files: ['<%= jshint.files %>'],
38
-      tasks: ['jshint']
61
+        scripts: {
62
+            files: ['<%= jshint.files %>'],
63
+            tasks: ['jshint', 'concat', 'uglify']
64
+        },
65
+        oscar_styles: {
66
+            files: ['less/oscar/**/*.less'],
67
+            tasks: ['less:development', 'less:production']
68
+        },
69
+        bootstrap_styles: {
70
+            files: ['less/bootstrap/**/*.less'],
71
+            tasks: ['less:bootstrap']
72
+        }
39 73
     }
40 74
   });
41 75
 
@@ -43,9 +77,12 @@ module.exports = function(grunt) {
43 77
   grunt.loadNpmTasks('grunt-contrib-jshint');
44 78
   grunt.loadNpmTasks('grunt-contrib-watch');
45 79
   grunt.loadNpmTasks('grunt-contrib-concat');
80
+  grunt.loadNpmTasks('grunt-contrib-less');
46 81
 
47 82
   grunt.registerTask('test', ['jshint']);
48 83
 
49
-  grunt.registerTask('default', ['jshint', 'concat', 'uglify']);
84
+  grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'less']);
85
+  
86
+  grunt.registerTask('styles', ['less']);
50 87
 
51 88
 };

+ 1
- 1
searx/static/themes/oscar/js/searx.min.js
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 79
- 0
searx/static/themes/oscar/less/oscar/code.less Bestand weergeven

@@ -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/themes/oscar/less/oscar/oscar.less Bestand weergeven

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

+ 5
- 0
searx/static/themes/oscar/less/oscar/results.less Bestand weergeven

@@ -55,6 +55,11 @@
55 55
     clear: both;
56 56
 }
57 57
 
58
+// code formating of results
59
+.result-code {
60
+    clear: both;
61
+}
62
+
58 63
 // suggestion
59 64
 .suggestion_item {
60 65
     margin: 2px 5px;

+ 2
- 1
searx/static/themes/oscar/package.json Bestand weergeven

@@ -4,7 +4,8 @@
4 4
         "grunt-contrib-uglify": "~0.6.0",
5 5
         "grunt-contrib-watch" : "~0.6.1",
6 6
         "grunt-contrib-concat" : "~0.5.0",
7
-        "grunt-contrib-jshint" : "~0.10.0"
7
+        "grunt-contrib-jshint" : "~0.10.0",
8
+        "grunt-contrib-less" : "~0.11.0"
8 9
     },
9 10
     
10 11
     "scripts": {

+ 9
- 0
searx/templates/courgette/result_templates/code.html Bestand weergeven

@@ -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 Bestand weergeven

@@ -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>

+ 25
- 0
searx/templates/oscar/macros.html Bestand weergeven

@@ -1,3 +1,28 @@
1
+<!-- Draw glyphicon icon from bootstrap-theme -->
1 2
 {% macro icon(action) -%}
2 3
     <span class="glyphicon glyphicon-{{ action }}"></span>
3 4
 {%- endmacro %}
5
+
6
+<!-- Draw favicon -->
7
+<!-- TODO: using url_for methode -->
8
+{% macro draw_favicon(favicon) -%}
9
+    <img width="32" height="32" class="favicon" src="static/themes/oscar/img/icons/{{ favicon }}.png" alt="{{ favicon }}" />
10
+{%- endmacro %}
11
+
12
+<!-- Draw result header -->
13
+{% macro result_header(result, favicons) -%} 
14
+    <h4 class="result_header">{% if result.engine~".png" in favicons %}{{ draw_favicon(result.engine) }} {% endif %}<a href="{{ result.url }}">{{ result.title|safe }}</a></h4>
15
+{%- endmacro %}
16
+
17
+<!-- Draw result sub header -->
18
+{% macro result_sub_header(result) -%}
19
+    {% if result.publishedDate %}<time class="text-muted" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif %}
20
+    <small><a class="text-info" href="https://web.archive.org/web/{{ result.url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
21
+{%- endmacro %}
22
+
23
+<!-- Draw result footer -->
24
+{% macro result_footer(result) -%}
25
+    <div class="clearfix"></div>
26
+    <span class="label label-default pull-right">{{ result.engine }}</span>
27
+    <p class="text-muted">{{ result.pretty_url }}</p>
28
+{%- endmacro %}

+ 12
- 0
searx/templates/oscar/result_templates/code.html Bestand weergeven

@@ -0,0 +1,12 @@
1
+{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, icon %}
2
+
3
+{{ result_header(result, favicons) }}
4
+{{ result_sub_header(result) }}
5
+
6
+{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
7
+
8
+{% if result.repository %}<p class="result-content">{{ icon('file') }} <a href="{{ result.repository|safe }}">{{ result.repository }}</a></p>{% endif %}
9
+
10
+{{ result.codelines|code_highlighter(result.code_language)|safe }}
11
+
12
+{{ result_footer(result) }}

+ 4
- 9
searx/templates/oscar/result_templates/default.html Bestand weergeven

@@ -1,9 +1,7 @@
1
-{% from 'oscar/macros.html' import icon %}
1
+{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, icon %}
2 2
 
3
-<h4 class="result_header">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="{{ url_for('static', filename='img/icons/'+result.engine+'.png') }}" alt="{{ result.engine }}" /> {% 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>
3
+{{ result_header(result, favicons) }}
4
+{{ result_sub_header(result) }}
7 5
 
8 6
 {% if result.embedded %}
9 7
     <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">{{ icon('music') }} {{ _('show media') }}</a></small>
@@ -17,7 +15,4 @@
17 15
 
18 16
 {% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
19 17
 
20
-<div class="clearfix"></div>
21
-
22
-<span class="label label-default pull-right">{{ result.engine }}</span>
23
-<p class="text-muted">{{ result.pretty_url }}</p>
18
+{{ result_footer(result) }}

+ 3
- 1
searx/templates/oscar/result_templates/images.html Bestand weergeven

@@ -1,3 +1,5 @@
1
+{% from 'oscar/macros.html' import draw_favicon %}
2
+
1 3
 <a href="{{ result.img_src }}" data-toggle="modal" data-target="#modal-{{ index }}">
2 4
     <img src="{{ result.img_src }}" alt="{{ result.title|striptags }}" title="{{ result.title|striptags }}" class="img-thumbnail">
3 5
 </a>
@@ -7,7 +9,7 @@
7 9
         <div class="modal-content">
8 10
             <div class="modal-header">
9 11
                 <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
10
-                <h4 class="modal-title">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="static/{{ theme }}/img/icons/{{ result.engine }}.png" alt="{{ result.engine }}" /> {% endif %}{{ result.title|striptags }}</h4>
12
+                <h4 class="modal-title">{% if result.engine~".png" in favicons %}{{ draw_favicon(result.engine) }} {% endif %}{{ result.title|striptags }}</h4>
11 13
             </div>
12 14
             <div class="modal-body">
13 15
                 <img class="img-responsive center-block" src="{{ result.img_src }}" alt="{{ result.title }}">

+ 4
- 10
searx/templates/oscar/result_templates/map.html Bestand weergeven

@@ -1,10 +1,7 @@
1
-{% from 'oscar/macros.html' import icon %}
1
+{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, icon %}
2 2
 
3
-<h4 class="result_header">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="{{ url_for('static', filename='img/icons/'+result.engine+'.png') }}" alt="{{ result.engine }}" /> {% 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
-
7
-<small><a class="text-info" href="https://web.archive.org/web/{{ result.pretty_url }}">{{ icon('link') }} {{ _('cached') }}</a></small>
3
+{{ result_header(result, favicons) }}
4
+{{ result_sub_header(result) }}
8 5
 
9 6
 {% if (result.latitude and result.longitude) or result.boundingbox %}
10 7
     <small> &bull; <a class="text-info btn-collapse collapsed searx_init_map cursor-pointer disabled_if_nojs" data-toggle="collapse" data-target="#result-map-{{ index }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %} data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}">{{ icon('globe') }} {{ _('show map') }}</a></small>
@@ -68,7 +65,4 @@
68 65
     </div>
69 66
 {% endif %}
70 67
 
71
-<div class="clearfix"></div>
72
-
73
-<span class="label label-default pull-right">{{ result.engine }}</span>
74
-<p class="text-muted">{{ result.pretty_url }}</p>
68
+{{ result_footer(result) }}

+ 21
- 28
searx/templates/oscar/result_templates/torrent.html Bestand weergeven

@@ -1,28 +1,21 @@
1
-{% from 'oscar/macros.html' import icon %}
2
-
3
-<h4 class="result_header">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="{{ url_for('static', filename='img/icons/'+result.engine+'.png') }}" alt="{{ result.engine }}" /> {% 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
-{% if result.magnetlink %}<small> &bull; <a href="{{ result.magnetlink }}" class="magnetlink">{{ icon('magnet') }} {{ _('magnet link') }}</a></small>{% endif %}
8
-{% if result.torrentfile %}<small> &bull; <a href="{{ result.torrentfile }}" class="torrentfile">{{ icon('download-alt') }} {{ _('torrent file') }}</a></small>{% endif %}
9
-
10
-<p class="result-content">{{ icon('transfer') }} {{ _('Seeder') }} <span class="badge">{{ result.seed }}</span> &bull; {{ _('Leecher') }} <span class="badge">{{ result.leech }}</span>
11
-{% if result.filesize %}<br />{{ icon('floppy-disk') }} {{ _('Filesize') }} 
12
-    <span class="badge">
13
-        {% if result.filesize < 1024 %}{{ result.filesize }} {{ _('Bytes') }}
14
-        {% elif result.filesize < 1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024) }} {{ _('kiB') }}
15
-        {% elif result.filesize < 1024*1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024/1024) }} {{ _('MiB') }}
16
-        {% elif result.filesize < 1024*1024*1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024/1024/1024) }} {{ _('GiB') }}
17
-        {% else %}{{ '{0:0.2f}'.format(result.filesize/1024/1024/1024/1024) }} {{ _('TiB') }}{% endif %}
18
-    </span>{% endif %}
19
-{% if result.files %}<br />{{ icon('file') }} {{ _('Number of Files') }} <span class="badge">{{ result.files }}</span>{% endif %}
20
-
21
-{% if result.content %}<br />{{ result.content|safe }}{% endif %}
22
-
23
-</p>
24
-
25
-<div class="clearfix"></div>
26
-
27
-<span class="label label-default pull-right">{{ result.engine }}</span>
28
-<p class="text-muted">{{ result.pretty_url }}</p>
1
+{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, icon %}
2
+
3
+{{ result_header(result, favicons) }}
4
+{{ result_sub_header(result) }}
5
+
6
+<p class="result-content">{{ icon('transfer') }} {{ _('Seeder') }} <span class="badge">{{ result.seed }}</span> &bull; {{ _('Leecher') }} <span class="badge">{{ result.leech }}</span>
7
+{% if result.filesize %}<br />{{ icon('floppy-disk') }} {{ _('Filesize') }} 
8
+    <span class="badge">
9
+        {% if result.filesize < 1024 %}{{ result.filesize }} {{ _('Bytes') }}
10
+        {% elif result.filesize < 1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024) }} {{ _('kiB') }}
11
+        {% elif result.filesize < 1024*1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024/1024) }} {{ _('MiB') }}
12
+        {% elif result.filesize < 1024*1024*1024*1024 %}{{ '{0:0.2f}'.format(result.filesize/1024/1024/1024) }} {{ _('GiB') }}
13
+        {% else %}{{ '{0:0.2f}'.format(result.filesize/1024/1024/1024/1024) }} {{ _('TiB') }}{% endif %}
14
+    </span>{% endif %}
15
+{% if result.files %}<br />{{ icon('file') }} {{ _('Number of Files') }} <span class="badge">{{ result.files }}</span>{% endif %}
16
+
17
+{% if result.content %}<br />{{ result.content|safe }}{% endif %}
18
+
19
+</p>
20
+
21
+{{ result_footer(result) }}

+ 4
- 9
searx/templates/oscar/result_templates/videos.html Bestand weergeven

@@ -1,9 +1,7 @@
1
-{% from 'oscar/macros.html' import icon %}
1
+{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, icon %}
2 2
 
3
-<h4 class="result_header">{% if result.engine~".png" in favicons %}<img width="32" height="32" class="favicon" src="{{ url_for('static', filename='img/icons/'+result.engine+'.png') }}" alt="{{ result.engine }}" /> {% 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>
3
+{{ result_header(result, favicons) }}
4
+{{ result_sub_header(result) }}
7 5
 
8 6
 {% if result.embedded %}
9 7
     <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-video-{{ index }}" data-btn-text-collapsed="{{ _('show video') }}" data-btn-text-not-collapsed="{{ _('hide video') }}">{{ icon('film') }} {{ _('show video') }}</a></small>
@@ -22,7 +20,4 @@
22 20
     </div>
23 21
 </div>
24 22
 
25
-<div class="clearfix"></div>
26
-
27
-<span class="label label-default pull-right">{{ result.engine }}</span>
28
-<p class="text-muted">{{ result.pretty_url }}</p>
23
+{{ result_footer(result) }}

+ 51
- 0
searx/webapp.py Bestand weergeven

@@ -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
@@ -101,6 +104,54 @@ def get_locale():
101 104
     return locale
102 105
 
103 106
 
107
+# code-highlighter
108
+@app.template_filter('code_highlighter')
109
+def code_highlighter(codelines, language=None):
110
+    if not language:
111
+        language = 'text'
112
+
113
+    try:
114
+        # find lexer by programing language
115
+        lexer = get_lexer_by_name(language, stripall=True)
116
+    except:
117
+        # if lexer is not found, using default one
118
+        lexer = get_lexer_by_name('text', stripall=True)
119
+
120
+    html_code = ''
121
+    tmp_code = ''
122
+    last_line = None
123
+
124
+    # parse lines
125
+    for line, code in codelines:
126
+        if not last_line:
127
+            line_code_start = line
128
+
129
+        # new codeblock is detected
130
+        if last_line is not None and\
131
+           last_line + 1 != line:
132
+
133
+            # highlight last codepart
134
+            formatter = HtmlFormatter(linenos='inline',
135
+                                      linenostart=line_code_start)
136
+            html_code = html_code + highlight(tmp_code, lexer, formatter)
137
+
138
+            # reset conditions for next codepart
139
+            tmp_code = ''
140
+            line_code_start = line
141
+
142
+        # add codepart
143
+        tmp_code += code + '\n'
144
+
145
+        # update line
146
+        last_line = line
147
+
148
+    # highlight last codepart
149
+    formatter = HtmlFormatter(linenos='inline', linenostart=line_code_start)
150
+    html_code = html_code + highlight(tmp_code, lexer, formatter)
151
+
152
+    return html_code
153
+
154
+
104 155
 def get_base_url():
105 156
     if settings['server']['base_url']:
106 157
         hostname = settings['server']['base_url']

+ 1
- 0
setup.py Bestand weergeven

@@ -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 Bestand weergeven

@@ -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