From d3421eb75792b0a77d521c5c5ce14035f6496a5e Mon Sep 17 00:00:00 2001 From: Joey Hagedorn Date: Wed, 3 Jan 2007 23:05:04 +0000 Subject: Added syntax coloring for Diffs! Woo. Requires Pygments be installed: http://pygments.pocoo.org git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2620 ce84e21b-d406-0410-9b95-82705330c041 --- .../reports/templates/config_items/index.html | 5 ++++- .../reports/templatetags/syntax_coloring.py | 25 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/lib/Server/Reports/reports/templatetags/syntax_coloring.py (limited to 'src/lib/Server/Reports/reports') diff --git a/src/lib/Server/Reports/reports/templates/config_items/index.html b/src/lib/Server/Reports/reports/templates/config_items/index.html index 952172715..b6e4957a4 100644 --- a/src/lib/Server/Reports/reports/templates/config_items/index.html +++ b/src/lib/Server/Reports/reports/templates/config_items/index.html @@ -1,6 +1,9 @@ +{% load syntax_coloring %} + {% extends "base.html" %} {% block extra_header_info %} + {% endblock%} @@ -41,7 +44,7 @@ {% endif %}{% if not item.reason.current_exists %} Existance: This item does not currently exist on the host but is specified to exist in the configuration. {% endif %}{% if item.reason.current_diff %} -Unified Diff:
{{item.reason.current_diff}}
+Unified Diff:
{{item.reason.current_diff|syntaxhilight:"diff"}}
{% endif %}
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) -- cgit v1.2.3-1-g7c22