diff --git a/dpaste/models.py b/dpaste/models.py
index e9da20b..977b28c 100644
--- a/dpaste/models.py
+++ b/dpaste/models.py
@@ -52,9 +52,6 @@ class Snippet(models.Model):
ordering = ('-published',)
db_table = 'dpaste_snippet'
- def get_linecount(self):
- return len(self.content.splitlines())
-
@property
def remaining_views(self):
if self.expire_type == self.EXPIRE_ONETIME:
diff --git a/dpaste/templates/dpaste/snippet_pre.html b/dpaste/templates/dpaste/snippet_pre.html
index 510a4bd..b6c71c8 100644
--- a/dpaste/templates/dpaste/snippet_pre.html
+++ b/dpaste/templates/dpaste/snippet_pre.html
@@ -1 +1 @@
-{% load dpaste_tags %}
{% for line in snippet|highlight %}- {{ line|safe|default:" " }}
{% endfor %}
+{% load dpaste_tags %}{% for line in highlighted %}- {{ line|safe|default:" " }}
{% endfor %}
diff --git a/dpaste/templatetags/dpaste_tags.py b/dpaste/templatetags/dpaste_tags.py
index e8de74f..ba2270f 100644
--- a/dpaste/templatetags/dpaste_tags.py
+++ b/dpaste/templatetags/dpaste_tags.py
@@ -1,16 +1,9 @@
from django.template import Library
-from ..highlight import pygmentize
-
register = Library()
@register.filter
def in_list(value, arg):
return value in arg
-@register.filter
-def highlight(snippet):
- h = pygmentize(snippet.content, snippet.lexer)
- h = h.replace(u' ', u' ')
- h = h.replace(u'\t', ' ')
- return h.splitlines()
+
diff --git a/dpaste/views.py b/dpaste/views.py
index 4d2591c..726a201 100644
--- a/dpaste/views.py
+++ b/dpaste/views.py
@@ -2,7 +2,6 @@ import datetime
import difflib
import json
-import requests
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
@@ -22,7 +21,7 @@ from pygments.util import ClassNotFound
from .forms import EXPIRE_CHOICES, get_expire_values, SnippetForm
from .highlight import (LEXER_DEFAULT, LEXER_KEYS, LEXER_LIST,
- LEXER_WORDWRAP, PLAIN_CODE)
+ LEXER_WORDWRAP, PLAIN_CODE, pygmentize)
from .models import ONETIME_LIMIT, Snippet
template_globals = {
@@ -107,13 +106,18 @@ class SnippetDetailView(SnippetView, DetailView):
ctx = super(SnippetDetailView, self).get_context_data(**kwargs)
ctx.update(template_globals)
ctx.update({
- 'lines': range(snippet.get_linecount()),
+ 'highlighted': self.highlight_snippet().splitlines(),
'tree': tree,
'wordwrap': snippet.lexer in LEXER_WORDWRAP and 'True' or 'False',
- 'gist': getattr(settings, 'DPASTE_ENABLE_GIST', True),
})
return ctx
+ def highlight_snippet(self):
+ snippet = self.get_object()
+ h = pygmentize(snippet.content, snippet.lexer)
+ h = h.replace(u' ', u' ')
+ h = h.replace(u'\t', ' ')
+ return h
class SnippetRawView(SnippetDetailView):
"""
@@ -216,11 +220,20 @@ class SnippetDiffView(TemplateView):
return diff
+ def highlight_snippet(self, content):
+ h = pygmentize(content, 'diff')
+ h = h.replace(u' ', u' ')
+ h = h.replace(u'\t', ' ')
+ return h
+
def get_context_data(self, **kwargs):
+ diff = self.get_diff()
+ highlighted = self.highlight_snippet(diff.content)
ctx = super(SnippetDiffView, self).get_context_data(**kwargs)
ctx.update(template_globals)
ctx.update({
- 'snippet': self.get_diff(),
+ 'snippet': diff,
+ 'highlighted': highlighted.splitlines(),
'fileA': self.fileA,
'fileB': self.fileB,
})