Fixed a bug that raised an error if a lexer is unknown

This commit is contained in:
Martin Mahner 2013-09-27 19:27:46 +00:00
parent e34c46f9aa
commit bf39d704d7

View file

@ -107,6 +107,9 @@ class NakedHtmlFormatter(HtmlFormatter):
yield i, t yield i, t
def pygmentize(code_string, lexer_name=LEXER_DEFAULT): def pygmentize(code_string, lexer_name=LEXER_DEFAULT):
try:
lexer = lexer_name and get_lexer_by_name(lexer_name) \ lexer = lexer_name and get_lexer_by_name(lexer_name) \
or PythonLexer() or PythonLexer()
except Exception as e:
lexer = PythonLexer()
return highlight(code_string, lexer, NakedHtmlFormatter()) return highlight(code_string, lexer, NakedHtmlFormatter())