From 50c398625c6539c9b1e714f8d0dd277c3cfe5aa3 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 8 Aug 2007 03:41:46 -0400 Subject: syntax highlighting for all files (untested) --- bn_django/git_browse/templates/git_browse/blob.html | 8 +++++++- bn_django/git_browse/views.py | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'bn_django/git_browse') 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 @@

Size

{{ size|filesizeformat }}

Raw contents

-
{{ contents|escape|wordwrap:80 }}
+ {% if pretty_contents %} +
{{ pretty_diff }}
+ {% else %} + {% if contents %} +
{{ contents|escape|wordwrap:80 }}
+ {% else %}No contents{% endif %} + {% endif %} {% else %}

No such object: {{ hash }}

{% 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) -- cgit v1.2.3