snipt/utils/templatetags/pygmentize.py

19 lines
602 B
Python
Raw Normal View History

2015-11-04 18:57:04 -08:00
from django import template
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name
register = template.Library()
@register.filter
def pygmentize(text):
return highlight(text,
get_lexer_by_name('diff',
encoding='UTF-8'),
HtmlFormatter(linenos='table',
anchorlinenos=True,
lineanchors='L',
linespans='L',
))