git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ed Schouten <ed@fxq.nl>
To: git@vger.kernel.org
Subject: Syntax highlighting for gitweb
Date: Mon, 26 Feb 2007 19:18:58 +0100	[thread overview]
Message-ID: <20070226181858.GC11232@hoeg.nl> (raw)

[-- 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 --]

             reply	other threads:[~2007-02-26 18:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-26 18:18 Ed Schouten [this message]
2007-02-26 18:55 ` Syntax highlighting for gitweb Johannes Schindelin
2007-02-27  1:45   ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070226181858.GC11232@hoeg.nl \
    --to=ed@fxq.nl \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).