mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
Some logging in highlight code.
This commit is contained in:
parent
d040f2959d
commit
9c45b92910
1 changed files with 9 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer
|
||||
from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer, PythonLexer
|
||||
from pygments.styles import get_all_styles
|
||||
from pygments.formatters import HtmlFormatter
|
||||
from pygments.util import ClassNotFound
|
||||
|
@ -38,8 +38,15 @@ class NakedHtmlFormatter(HtmlFormatter):
|
|||
|
||||
def pygmentize(code_string, lexer_name='text'):
|
||||
try:
|
||||
return highlight(code_string, get_lexer_by_name(lexer_name), NakedHtmlFormatter())
|
||||
lexer = get_lexer_by_name(lexer_name)
|
||||
except ClassNotFound:
|
||||
logger.warning('Could not find lexer for name "%s"' % lexer_name)
|
||||
lexer = PythonLexer()
|
||||
|
||||
try:
|
||||
return highlight(code_string, lexer, NakedHtmlFormatter())
|
||||
except TypeError:
|
||||
logger.warning('Could not highlight code with lexer "%s"' % lexer_name)
|
||||
return code_string
|
||||
|
||||
def guess_code_lexer(code_string, default_lexer='unknown'):
|
||||
|
|
Loading…
Reference in a new issue