aboutsummaryrefslogtreecommitdiffstats
path: root/bn_django
diff options
context:
space:
mode:
Diffstat (limited to 'bn_django')
-rw-r--r--bn_django/git_browse/templates/git_browse/blob.html8
-rw-r--r--bn_django/git_browse/views.py10
2 files changed, 16 insertions, 2 deletions
diff --git a/bn_django/git_browse/templates/git_browse/blob.html b/bn_django/git_browse/templates/git_browse/blob.html
index 4a0304c..853c034 100644
--- a/bn_django/git_browse/templates/git_browse/blob.html
+++ b/bn_django/git_browse/templates/git_browse/blob.html
@@ -6,7 +6,13 @@
<h3>Size</h3>
{{ size|filesizeformat }}<br />
<h3>Raw contents</h3>
- <pre class="large">{{ contents|escape|wordwrap:80 }}</pre>
+ {% if pretty_contents %}
+ <pre class="large">{{ pretty_diff }}</pre>
+ {% else %}
+ {% if contents %}
+ <pre class="large">{{ contents|escape|wordwrap:80 }}</pre>
+ {% else %}No contents{% endif %}
+ {% endif %}
{% else %}
<h3>No such object: {{ hash }}</h3>
{% endif %} {% endblock %}
diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py
index 79b3573..23b0191 100644
--- a/bn_django/git_browse/views.py
+++ b/bn_django/git_browse/views.py
@@ -104,6 +104,13 @@ def view_blob(request, repo, hash):
(GITPREFIX, heads, tags) = therepo.scan()
b = Blob(id=hash,repo=therepo)
b.update()
+ try:
+ from pygments import highlight
+ from pygments.lexers import guess_lexer
+ from pygments.formatters import HtmlFormatter
+ b.pretty_contents = highlight(b.contents, guess_lexer(b.contents), HtmlFormatter())
+ except:
+ b.pretty_contents = None
return render_to_response('git_browse/blob.html',
dict(object=therepo,
@@ -111,7 +118,8 @@ def view_blob(request, repo, hash):
tags=tags,
hash=b.id,
size=b.size,
- contents=b.contents))
+ contents=b.contents,
+ pretty_contents=b.pretty_contents))
def view_commit(request, repo, hash):
therepo = get_object_or_404(Repository, slug=repo)