diff options
author | bnewbold <bnewbold@manus.(none)> | 2007-08-08 03:41:46 -0400 |
---|---|---|
committer | bnewbold <bnewbold@manus.(none)> | 2007-08-08 03:41:46 -0400 |
commit | 50c398625c6539c9b1e714f8d0dd277c3cfe5aa3 (patch) | |
tree | 38b001a2bc112fbdafd3208374b5aaadd1db0cc3 | |
parent | 9581828aa8489b7f09f1f6bf627faf231789cf84 (diff) | |
download | bnewnet-50c398625c6539c9b1e714f8d0dd277c3cfe5aa3.tar.gz bnewnet-50c398625c6539c9b1e714f8d0dd277c3cfe5aa3.zip |
syntax highlighting for all files (untested)
-rw-r--r-- | bn_django/git_browse/templates/git_browse/blob.html | 8 | ||||
-rw-r--r-- | bn_django/git_browse/views.py | 10 |
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) |