@matheusbsbs / matheus-bagliano / commits / 6255ef08ae
Fork 0

gitweb: Better support for non-CSS aware web browsers

Add option to replace SPC (' ') with hard (non-breakable) space HTML entity '&nbsp;' in esc_html subroutine. Replace ' ' with '&nbsp;' for the code/diff display part in git_blob and git_patchset_body; this is to be able to view code and diffs in web browsers which doesn't understand "white-space: pre;" CSS declaration. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Nov 1, 2006 at 14:33 UTC 6255ef08ae746bdad34851297a989ad6f36f6a21
1 file changed +8 -3
gitweb/gitweb.perl
+8 -3
@@ -554,12 +554,17 @@ sub esc_url {
554 }
555
556 # replace invalid utf8 character with SUBSTITUTION sequence
557 -sub esc_html {
557 +sub esc_html ($;%) {
558 my $str = shift;
559 + my %opts = @_;
560 +
561 $str = to_utf8($str);
562 $str = escapeHTML($str);
563 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
564 $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1)
565 + if ($opts{'-nbsp'}) {
566 + $str =~ s/ /&nbsp;/g;
567 + }
568 return $str;
569 }
570
@@ -784,7 +789,7 @@ sub format_diff_line {
789 $diff_class = " incomplete";
790 }
791 $line = untabify($line);
787 - return "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
792 + return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
793 }
794
795 ## ----------------------------------------------------------------------
@@ -2944,7 +2949,7 @@ sub git_blob {
2949 $nr++;
2950 $line = untabify($line);
2951 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2947 - $nr, $nr, $nr, esc_html($line);
2952 + $nr, $nr, $nr, esc_html($line, -nbsp=>1);
2953 }
2954 close $fd
2955 or print "Reading blob failed.\n";