From c21fcbc9cb3837495549161817f5d02dd9be5d3b Mon Sep 17 00:00:00 2001 From: bnewbold Date: Fri, 1 Jun 2007 02:27:17 -0400 Subject: pygments highlighting for wiki commits --- bn_django/git_wiki/templates/git_wiki/commit.html | 14 ++++-- bn_django/git_wiki/views.py | 6 +++ static/style/pygments-default.css | 58 +++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 static/style/pygments-default.css diff --git a/bn_django/git_wiki/templates/git_wiki/commit.html b/bn_django/git_wiki/templates/git_wiki/commit.html index 8497311..82aace4 100644 --- a/bn_django/git_wiki/templates/git_wiki/commit.html +++ b/bn_django/git_wiki/templates/git_wiki/commit.html @@ -1,5 +1,9 @@ {% extends "git_wiki/base.html" %} +{% block stylesheets %}{{ block.super }} + +{% endblock %} + {% block title %}Commit: {{ commit.committer_date}} {% endblock %} {% block gitwiki %} {% if commit %} @@ -23,9 +27,13 @@ {{ commit.committer }}
Committer Date: {{ commit.committer_date }}
- {% if commit.rawdiff %} -
{{ commit.rawdiff }}
- {% else %}No diff{% endif %} + {% if commit.pretty_diff %} +
{{ commit.pretty_diff}}
+ {% else %} + {% if commit.rawdiff %} +
{{ commit.rawdiff }}
+ {% else %}No difference?{% endif %} + {% endif %} {% else %}

No such object: {{ hash }}

{% endif %} {% endblock %} diff --git a/bn_django/git_wiki/views.py b/bn_django/git_wiki/views.py index 5a4efbd..dcd1646 100644 --- a/bn_django/git_wiki/views.py +++ b/bn_django/git_wiki/views.py @@ -224,6 +224,12 @@ def view_commit(request, hash): c = Commit(id=hash) c.update() + from pygments import highlight + from pygments.lexers import DiffLexer + from pygments.formatters import HtmlFormatter + + c.pretty_diff = highlight(c.rawdiff, DiffLexer(), HtmlFormatter()) + return render_to_response('git_wiki/commit.html', dict(heads=heads, tags=tags, commit=c)) diff --git a/static/style/pygments-default.css b/static/style/pygments-default.css new file mode 100644 index 0000000..67456ac --- /dev/null +++ b/static/style/pygments-default.css @@ -0,0 +1,58 @@ +.c { color: #008800; font-style: italic } /* Comment */ +.err { border: 1px solid #FF0000 } /* Error */ +.k { color: #AA22FF; font-weight: bold } /* Keyword */ +.o { color: #666666 } /* Operator */ +.cm { color: #008800; font-style: italic } /* Comment.Multiline */ +.cp { color: #008800 } /* Comment.Preproc */ +.c1 { color: #008800; font-style: italic } /* Comment.Single */ +.cs { color: #008800; font-weight: bold } /* Comment.Special */ +.gd { color: #A00000 } /* Generic.Deleted */ +.ge { font-style: italic } /* Generic.Emph */ +.gr { color: #FF0000 } /* Generic.Error */ +.gh { color: #000080; font-weight: bold } /* Generic.Heading */ +.gi { color: #00A000 } /* Generic.Inserted */ +.go { color: #808080 } /* Generic.Output */ +.gp { color: #000080; font-weight: bold } /* Generic.Prompt */ +.gs { font-weight: bold } /* Generic.Strong */ +.gu { color: #800080; font-weight: bold } /* Generic.Subheading */ +.gt { color: #0040D0 } /* Generic.Traceback */ +.kc { color: #AA22FF; font-weight: bold } /* Keyword.Constant */ +.kd { color: #AA22FF; font-weight: bold } /* Keyword.Declaration */ +.kp { color: #AA22FF } /* Keyword.Pseudo */ +.kr { color: #AA22FF; font-weight: bold } /* Keyword.Reserved */ +.kt { color: #AA22FF; font-weight: bold } /* Keyword.Type */ +.m { color: #666666 } /* Literal.Number */ +.s { color: #BB4444 } /* Literal.String */ +.na { color: #BB4444 } /* Name.Attribute */ +.nb { color: #AA22FF } /* Name.Builtin */ +.nc { color: #0000FF } /* Name.Class */ +.no { color: #880000 } /* Name.Constant */ +.nd { color: #AA22FF } /* Name.Decorator */ +.ni { color: #999999; font-weight: bold } /* Name.Entity */ +.ne { color: #D2413A; font-weight: bold } /* Name.Exception */ +.nf { color: #00A000 } /* Name.Function */ +.nl { color: #A0A000 } /* Name.Label */ +.nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ +.nt { color: #008000; font-weight: bold } /* Name.Tag */ +.nv { color: #B8860B } /* Name.Variable */ +.ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ +.mf { color: #666666 } /* Literal.Number.Float */ +.mh { color: #666666 } /* Literal.Number.Hex */ +.mi { color: #666666 } /* Literal.Number.Integer */ +.mo { color: #666666 } /* Literal.Number.Oct */ +.sb { color: #BB4444 } /* Literal.String.Backtick */ +.sc { color: #BB4444 } /* Literal.String.Char */ +.sd { color: #BB4444; font-style: italic } /* Literal.String.Doc */ +.s2 { color: #BB4444 } /* Literal.String.Double */ +.se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ +.sh { color: #BB4444 } /* Literal.String.Heredoc */ +.si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ +.sx { color: #008000 } /* Literal.String.Other */ +.sr { color: #BB6688 } /* Literal.String.Regex */ +.s1 { color: #BB4444 } /* Literal.String.Single */ +.ss { color: #B8860B } /* Literal.String.Symbol */ +.bp { color: #AA22FF } /* Name.Builtin.Pseudo */ +.vc { color: #B8860B } /* Name.Variable.Class */ +.vg { color: #B8860B } /* Name.Variable.Global */ +.vi { color: #B8860B } /* Name.Variable.Instance */ +.il { color: #666666 } /* Literal.Number.Integer.Long */ -- cgit v1.2.3