From 1a913441678e756c220a767c7d955912648921ba Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 7 Sep 2010 14:43:00 +0200 Subject: [PATCH 1/5] gitweb: Allow line number toggling with Javascript Signed-off-by: Johannes Schindelin --- gitweb/gitweb.perl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 7a5b23acf2..54858dcae8 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4547,6 +4547,25 @@ sub git_print_page_path { print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name, hash_base=>$hb), -title => $name}, esc_path($basename)); + print '     + + +'; } elsif (defined $type && $type eq 'tree') { print $cgi->a({-href => href(action=>"tree", file_name=>$file_name, hash_base=>$hb), From 1b23108be0c1091dd16af5ed1b80c2ad22e779bf Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 7 Sep 2010 16:58:16 +0200 Subject: [PATCH 2/5] Gitweb: make line number toggling work for Firefox and Safari Signed-off-by: Johannes Schindelin --- gitweb/gitweb.perl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 54858dcae8..6390a1c565 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4562,7 +4562,9 @@ function toggleLineNumbers() { e2.innerHTML = "[Hide line numbers]"; } } -document.getElementsByTagName("head")[0].innerHTML += ""; +var style = document.createElement("style"); +style.setAttribute("id", "lineNoStyle"); +document.getElementsByTagName("head")[0].appendChild(style); toggleLineNumbers(); '; From 983d1216ab7efa631555909533eb554474699720 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 25 Sep 2011 03:02:57 -0500 Subject: [PATCH 3/5] 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 6390a1c565..f43dabcfbb 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -7079,7 +7079,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; @@ -7127,6 +7139,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>) {

From 3a51b4fe13c13971862dbab7390baa391b04f69f Mon Sep 17 00:00:00 2001
From: Johannes Schindelin 
Date: Sun, 25 Sep 2011 10:23:29 +0200
Subject: [PATCH 4/5] Only switch on the line number toggle when highlighting
 is activated

Signed-off-by: Johannes Schindelin 
---
 gitweb/gitweb.perl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f43dabcfbb..d738c7465b 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4547,7 +4547,8 @@ sub git_print_page_path {
 			print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
 			                             hash_base=>$hb),
 			              -title => $name}, esc_path($basename));
-			print '    
+			if (gitweb_check_feature('highlight')) {
+				print '    
 
 
 ';
+			}
 		} elsif (defined $type && $type eq 'tree') {
 			print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
 			                             hash_base=>$hb),

From 3024056cae212dfe21411722b5c9509532862c5b Mon Sep 17 00:00:00 2001
From: Johannes Schindelin 
Date: Mon, 26 Sep 2011 20:53:09 +0200
Subject: [PATCH 5/5] gitweb (SyntaxHighlighter): interpret #l

It is pretty convenient to refer to a line number by appending, say,
highlighter, too.

Signed-off-by: Johannes Schindelin 
---
 gitweb/gitweb.perl | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d738c7465b..ab8c382c59 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -7192,7 +7192,21 @@ sub git_blob {
 			$lang =~ s! (\S+)$! $brush_prefix$1!;
 			print "'".$lang.qq!.js',!;
 		}
-		print qq!''); SyntaxHighlighter.all();!;
+		print qq!''); SyntaxHighlighter.all();!
+			.qq!function scrollTo(number) {!
+			.qq!  var elements = document.getElementsByClassName(number);!
+			.qq!  if (elements.length == 0) setTimeout('scrollTo("' + number + '");', 50);!
+			.qq!  else {!
+			.qq!    window.scroll(0, elements[0].offsetTop);!
+			.qq!    window.scrollTo(0, elements[0].offsetTop);!
+			.qq!    elements[0].style.color = '#ff0000';!
+			.qq!  }!
+			.qq!}!
+			.qq!var lineRegex = /#l(\\d+)\$/;!
+			.qq!var lineNumber = lineRegex.exec(document.URL);!
+			.qq!if (lineNumber)!
+			.qq!  scrollTo('number' + lineNumber[1]);!
+			.qq!!;
 	} else {
 		my $nr;
 		while (my $line = <$fd>) {