summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2014-12-22 16:26:45 +0100
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2014-12-22 16:26:45 +0100
commitaf8dac93a8acff5042b7b399c38e348f0bdc32ad (patch)
treeefd4aab48cd0f97a01297d7870036633ad89dc92 /searx/webapp.py
parentd810763107733cec017b8688c0350dff527f2ed1 (diff)
[enh] fix pep8, improve syntax highlighting
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 11db1bf2e..ab1e2747f 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -99,9 +99,13 @@ def code_highlighter(codelines, language=None):
if not language:
language = 'text'
- # find lexer by programing language
- lexer = get_lexer_by_name(language, stripall=True)
-
+ try:
+ # find lexer by programing language
+ lexer = get_lexer_by_name(language, stripall=True)
+ except:
+ # if lexer is not found, using default one
+ lexer = get_lexer_by_name('text', stripall=True)
+
html_code = ''
tmp_code = ''
last_line = None
@@ -112,20 +116,21 @@ def code_highlighter(codelines, language=None):
line_code_start = line
# new codeblock is detected
- if last_line != None and\
- last_line +1 != line:
+ if last_line is not None and\
+ last_line + 1 != line:
# highlight last codepart
- formatter = HtmlFormatter(linenos='inline', linenostart=line_code_start)
+ formatter = HtmlFormatter(linenos='inline',
+ linenostart=line_code_start)
html_code = html_code + highlight(tmp_code, lexer, formatter)
-
+
# reset conditions for next codepart
tmp_code = ''
line_code_start = line
# add codepart
tmp_code += code + '\n'
-
+
# update line
last_line = line