git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Syntax highlighting for gitweb
@ 2007-02-26 18:18 Ed Schouten
  2007-02-26 18:55 ` Johannes Schindelin
  0 siblings, 1 reply; 3+ messages in thread
From: Ed Schouten @ 2007-02-26 18:18 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 1515 bytes --]

Hello everyone,

I just wrote a really awful patch to add syntax highlighting to gitweb:

%%%
--- gitweb	Mon Feb 26 18:36:42 2007
+++ gitweb	Mon Feb 26 19:12:20 2007
@@ -16,6 +16,7 @@
 use Fcntl ':mode';
 use File::Find qw();
 use File::Basename qw(basename);
+use IPC::Open2;
 binmode STDOUT, ':utf8';
 
 our $cgi = new CGI;
@@ -3186,15 +3187,25 @@
 	git_print_page_path($file_name, "blob", $hash_base);
 	print "<div class=\"page_body\">\n";
 	my $nr;
+
+	my $pid;
+	local (*HLR, *HLW);
+	$pid = open2(\*HLR, \*HLW, "highlight -f --syntax c");
 	while (my $line = <$fd>) {
-		chomp $line;
-		$nr++;
-		$line = untabify($line);
-		printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
-		       $nr, $nr, $nr, esc_html($line, -nbsp=>1);
+		print HLW $line;
 	}
+	close HLW
+		or print "Failed to start highlight.\n";
 	close $fd
 		or print "Reading blob failed.\n";
+
+	while (my $line = <HLR>) {
+		$nr++;
+		printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
+		       $nr, $nr, $nr, $line;
+	}
+	close HLR
+		or print "Failed to highlight blob.\n";
 	print "</div>";
 	git_footer_html();
 }
%%%

I am not a Perl programmer, so I kept it really simple by just
hardcoding '--syntax c'. Would it be possible for some real Perl
programmer to clean this up? I think a feature like this would be really
cool to have.

Yours,
-- 
 Ed Schouten <ed@fxq.nl>
 WWW: http://g-rave.nl/

[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-02-27  1:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-26 18:18 Syntax highlighting for gitweb Ed Schouten
2007-02-26 18:55 ` Johannes Schindelin
2007-02-27  1:45   ` Jakub Narebski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).