gitweb: Syntax highlighting support
From: Johannes Schindelin <[email protected]>
It requires the 'highlight' program to do all the heavy-lifting:
http://www.andre-simon.de / http://wiki.andre-simon.de
This is loosely based on Daniel Svensson's and Sham Chukoury's work in gitweb-xmms2.git (it cannot be cherry-picked, as gitweb-xmms2 first forked wildly, then not contributed back, and then went stale).
[jn: cherry picked from bc1ed6aafd9ee4937559535c66c8bddf1864bec6
in http://repo.or.cz/w/git/dscho.git, with a few changes]
---
This is a RFC, because there exist other syntax highlighters that can function as filter (take input from STDIN, and write result to STDOUT), and have (X)HTML among supported output formats. Beside 'highlight' by Andre Simon, there is also 'source-highlight' (GNU Source Highlight), and probably other programs.
It would be nice to be able to configure which program to use. The question is if it should be configurable in per-repository basis, or there should be global (per gitweb configuration) highlighter, while highlighting can be turned on and off in per-repository basis.
The list of supported extensions is widened, but I see that I fotgot to include syntax highlighting for Perl.
Compared to the version in Dscho repository, it makes gitweb do line numbering by itself, instead of making 'highlight' do it... and then rewriting it to conform to the rest of gitweb. We should probably leave tab expansion to gitweb, so that 'blob' view would look the same with and without syntax hightlighting enabled.
Note that gitweb.css contains default 'highlight' style, but perhaps other style would be better fit for deafule gitweb CSS.
WARNING: No tests!
Have fun playing with it!
gitweb/gitweb.css | 18 ++++++++++++++++ gitweb/gitweb.perl | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 2 deletions(-)
gitweb/gitweb.css +18 -0
@@ -572,3 +572,21 @@ span.match { div.binary { font-style: italic; } + +/* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */ + +/* Highlighting theme definition: */ + +.num { color:#2928ff; } +.esc { color:#ff00ff; } +.str { color:#ff0000; } +.dstr { color:#818100; } +.slc { color:#838183; font-style:italic; } +.com { color:#838183; font-style:italic; } +.dir { color:#008200; } +.sym { color:#000000; } +.line { color:#555555; } +.kwa { color:#000000; font-weight:bold; } +.kwb { color:#830000; } +.kwc { color:#000000; font-weight:bold; } +.kwd { color:#010181; }
gitweb/gitweb.perl +55 -2
89 lines not on this page · raw message
Hi,
Quoted 2 lines · Jakub Narebski
[jn: cherry picked from
bc1ed6aafd9ee4937559535c66c8bddf1864bec6
in http://repo.or.cz/w/git/dscho.git, with a few changes]
Thanks. These changes are greatly appreciated, and I will try to find the time to install this in our production system tomorrow.
Ciao,
Dscho
Quoted 7 lines · Johannes Schindelin
Quoted 2 lines · Jakub Narebski
[jn: cherry picked from
bc1ed6aafd9ee4937559535c66c8bddf1864bec6
in http://repo.or.cz/w/git/dscho.git, with a few changes]Thanks. These changes are greatly appreciated, and I will try to find the time to install this in our production system tomorrow.
This patch is also available in 'gitweb/web' branch in my repository:
http://repo.or.cz/w/git/jnareb-git.git
P.S. I have applied your patch "cherry-picking" it from your repository by saving 'patch' view from gitweb and using git-am on it. You can pull
git://repo.or.cz/git/jnareb-git.git gitweb/web
or you can do the same
http://repo.or.cz/w/git/jnareb-git.git/patch/7bf179bb5c40518b98bc63ebcfa3ae7f0b437a42
Signature · 2 lines
Jakub Narebski Poland
Quoted 4 lines · Jakub Narebski
From: Johannes Schindelin <[email protected]>
It requires the 'highlight' program to do all the heavy-lifting:
http://www.andre-simon.de / http://wiki.andre-simon.de
[...]
Quoted 6 lines
---
This is a RFC, because there exist other syntax highlighters that can function as filter (take input from STDIN, and write result to STDOUT), and have (X)HTML among supported output formats. Beside 'highlight' by Andre Simon, there is also 'source-highlight' (GNU Source Highlight), and probably other programs.
Actually GNU Source Highlight (http://www.gnu.org/software/src-highlite)
as it is now wouldn't be a good fit for gitweb, because it lacks equivalent of Highlight '--fragment' option; even with '--no-doc' it prefixes contents with some comments and wraps the whole with <pre><tt> tags.
On the other hand side one can also use Perl modules from CPAN for syntax highlighting. It would be nice to have this option for syntax highlighting in gitweb.
Signature · 3 lines
Jakub Narebski Poland ShadeHawk on #git