From 85312b173d0d3802346fbbca8e6b06f3d6d2b17c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 25 Sep 2011 03:02:57 -0500 Subject: [PATCH] Gitweb: add support for Alex Gorbatchev's SyntaxHighlighter in Javascript Gitweb is not exactly what you would call server-friendly, so let's offload one more task onto the client. To enable this, put something like this into your gitweb_config.perl: $feature{'syntaxhighlighter_js'}{'default'} = [{ url => '/SyntaxHighlighter/', style => 'Django', theme => 'FadeToGrey' }]; and clone git://github.com/alexgorbatchev/SyntaxHighlighter into the directory you specified via the 'url' parameter. Signed-off-by: Johannes Schindelin --- gitweb/gitweb.perl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index fc8cabff91..8fdda5b711 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -6979,7 +6979,19 @@ sub git_blob { # we can have blame only for text/* mimetype $have_blame &&= ($mimetype =~ m!^text/!); + my $highlight_js = gitweb_check_feature('syntaxhighlighter_js'); + if ($highlight_js) { + push @stylesheets, $highlight_js->{url} . '/styles/shCore' + . $highlight_js->{style} . '.css'; + push @stylesheets, $highlight_js->{url} . '/styles/shTheme' + . $highlight_js->{theme} . '.css'; + } + my $highlight = gitweb_check_feature('highlight'); + if ($highlight_js && $highlight) { + die_error(500, 'The highlight and syntaxhighlighter_js are' + . 'mutually exclusive'); + } my $syntax = guess_file_syntax($highlight, $mimetype, $file_name); $fd = run_highlighter($fd, $highlight, $syntax) if $syntax; @@ -7027,6 +7039,58 @@ sub git_blob { href(action=>"blob_plain", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name) . qq!" />\n!; + } elsif ($highlight_js) { + my $ext = $file_name; + $ext =~ s/.*\.//; + print qq!
!;
+		while (my $line = <$fd>) {
+			$line =~ s!&!\&!g;
+			$line =~ s!!;
+		foreach my $name ('Core', 'Autoloader') {
+			print qq!!;
+		}
+		print qq!!;
 	} else {
 		my $nr;
 		while (my $line = <$fd>) {
-- 
2.11.4.GIT