mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-12-23 23:23:06 +11:00
Alternative snippet highlighting using a templatetag which might work better than having it on-save.
This commit is contained in:
parent
f6648037cf
commit
e38a7b89ab
2 changed files with 11 additions and 1 deletions
|
@ -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 %} {% 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 %} {% endif %}</div>{% endfor %}</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -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()
|
Loading…
Reference in a new issue