Alternative snippet highlighting using a templatetag which might work better than having it on-save.

This commit is contained in:
Martin Mahner 2011-06-11 14:19:16 +02:00
parent f6648037cf
commit e38a7b89ab
2 changed files with 11 additions and 1 deletions

View file

@ -49,7 +49,7 @@
<table>
<tr>
<th><pre class="code">{% for l in lines %}<a href="#l{{ forloop.counter }}" id="l{{ forloop.counter }}">{{ forloop.counter }}</a>{% endfor %}</pre></th>
<td><pre class="code">{% for line in snippet.content_splitted %}<div class="line" id="l{{ forloop.counter }}">{% if line %}{{ line|safe }}{% else %}&nbsp;{% endif %}</div>{% endfor %}</pre></td>
<td><pre class="code">{% for line in snippet|highlight %}<div class="line" id="l{{ forloop.counter }}">{% if line %}{{ line|safe }}{% else %}&nbsp;{% endif %}</div>{% endfor %}</pre></td>
</tr>
</table>
</div>

View file

@ -1,7 +1,17 @@
from django.template import Library
from django.utils.safestring import mark_safe
from pastebin.apps.dpaste.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)
if not h:
return snippet.content.splitlines()
return h.splitlines()