mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-12-23 23:23:06 +11:00
Pygments 0.6 downgrade.
This commit is contained in:
parent
2734acb627
commit
db0e060b30
1 changed files with 4 additions and 6 deletions
|
@ -1,7 +1,5 @@
|
|||
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
|
||||
from pygments import highlight
|
||||
|
||||
from django.utils.html import escape
|
||||
|
@ -41,18 +39,18 @@ class NakedHtmlFormatter(HtmlFormatter):
|
|||
def pygmentize(code_string, lexer_name=LEXER_DEFAULT):
|
||||
try:
|
||||
lexer = get_lexer_by_name(lexer_name)
|
||||
except ClassNotFound:
|
||||
logger.warning('Could not find lexer for name "%s"' % lexer_name)
|
||||
except ValueError:
|
||||
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)
|
||||
logger.warning('Could not highlight code with lexer "%s"' % lexer_name)
|
||||
return escape(code_string)
|
||||
|
||||
def guess_code_lexer(code_string, default_lexer='unknown'):
|
||||
try:
|
||||
return guess_lexer(code_string).name
|
||||
except ClassNotFound:
|
||||
except ValueError:
|
||||
return default_lexer
|
||||
|
|
Loading…
Reference in a new issue