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):
|
2019-01-23 15:52:55 -08:00
|
|
|
return highlight(
|
|
|
|
text,
|
|
|
|
get_lexer_by_name("diff", encoding="UTF-8"),
|
|
|
|
HtmlFormatter(
|
|
|
|
linenos="table", anchorlinenos=True, lineanchors="L", linespans="L"
|
|
|
|
),
|
|
|
|
)
|