summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Server/Reports/reports/templatetags/syntax_coloring.py')
-rw-r--r--src/lib/Server/Reports/reports/templatetags/syntax_coloring.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py b/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py
new file mode 100644
index 000000000..14827b3c6
--- /dev/null
+++ b/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py
@@ -0,0 +1,25 @@
+from django import template
+
+try:
+ from pygments import highlight
+ from pygments.lexers import get_lexer_by_name
+ from pygments.formatters import HtmlFormatter
+ colorize = True
+except:
+ colorize = False
+
+register = template.Library()
+
+def syntaxhilight(value, arg="diff"):
+ '''Returns a syntax-hilighted version of Code; requires code and language arguments'''
+ lexer = get_lexer_by_name(arg)
+ if colorize:
+ try:
+ return highlight(value, lexer, HtmlFormatter())
+ except:
+ return value
+ else:
+ return value
+
+
+register.filter('syntaxhilight', syntaxhilight)