All of lore.kernel.org
 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

* Re: Syntax highlighting for gitweb
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin @ 2007-02-26 18:55 UTC (permalink / raw)
  To: Ed Schouten; +Cc: git

Hi,

On Mon, 26 Feb 2007, Ed Schouten wrote:

> I just wrote a really awful patch to add syntax highlighting to gitweb:
> 
> [...]
>
> +	$pid = open2(\*HLR, \*HLW, "highlight -f --syntax c");

Since this fork()s an external program, which is possibly expensive, or 
can fail because the program is not there, you should at least

- document it, and
- make it optional.

Ciao,
Dscho

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

* Re: Syntax highlighting for gitweb
  2007-02-26 18:55 ` Johannes Schindelin
@ 2007-02-27  1:45   ` Jakub Narebski
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Narebski @ 2007-02-27  1:45 UTC (permalink / raw)
  To: git

Johannes Schindelin wrote:

> On Mon, 26 Feb 2007, Ed Schouten wrote:
> 
>> I just wrote a really awful patch to add syntax highlighting to gitweb:
>> 
>> [...]
>>
>> +    $pid = open2(\*HLR, \*HLW, "highlight -f --syntax c");
> 
> Since this fork()s an external program, which is possibly expensive, or 
> can fail because the program is not there, you should at least
> 
> - document it, and
> - make it optional.

It was planned (search for "[RFC] gitweb wishlist and TODO list" in
archives), and gitweb-xmms2 (http://git.xmms.se/?p=gitweb-xmms2.git)
has it: see http://git.or.cz/gitwiki/InterfacesFrontendsAndTools#gitweb
but it was postponed together with committags support to have git config
reader in Perl to use in gitweb.

Hmmm... perhaps we should use open2 in few places where we use non-list form
of magic open "-|" (the one which spawns shell)?
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

^ 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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.