New highlight try.

This commit is contained in:
Martin Mahner 2011-06-10 14:34:03 +02:00
parent c553fdf8f0
commit 4cdf648fc3
2 changed files with 13 additions and 9 deletions

View file

@ -38,15 +38,19 @@ class NakedHtmlFormatter(HtmlFormatter):
def pygmentize(code_string, lexer_name=LEXER_DEFAULT):
try:
lexer = get_lexer_by_name(lexer_name)
except ValueError:
logger.warning('Could not find lexer for name "%s"' % lexer_name)
lexer = PythonLexer()
if lexer_name:
lexer = get_lexer_by_name(lexer_name)
else:
raise Exception
except:
try:
lexer = guess_lexer(code_string)
except:
lexer = PythonLexer()
try:
return highlight(code_string, lexer, NakedHtmlFormatter())
except TypeError:
logger.warning('Could not highlight code with lexer "%s"' % lexer_name)
except:
return escape(code_string)
def guess_code_lexer(code_string, default_lexer='unknown'):

View file

@ -37,8 +37,8 @@ class Snippet(models.Model):
if not self.pk:
self.published = datetime.datetime.now()
self.secret_id = generate_secret_id()
#self.content_highlighted = pygmentize(self.content, self.lexer)
self.content_highlighted = self.content
if self.content and self.lexer:
self.content_highlighted = pygmentize(self.content, self.lexer)
super(Snippet, self).save(*args, **kwargs)
def get_absolute_url(self):