From: Jakub Narebski Date: Wed, 1 Nov 2006 13:33:21 +0000 (+0100) Subject: gitweb: Better support for non-CSS aware web browsers X-Git-Url: https://git.ladys.computer/Gitweb/commitdiff_plain/560aaf0f61c7270bb88a0e5d19f71df25618dc0b5b7fba3702b43af4c50445fb gitweb: Better support for non-CSS aware web browsers Add option to replace SPC (' ') with hard (non-breakable) space HTML entity ' ' in esc_html subroutine. Replace ' ' with ' ' 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 Signed-off-by: Junio C Hamano --- diff --git a/gitweb.perl b/gitweb.perl index 7bf096f..c2c296e 100755 --- a/gitweb.perl +++ b/gitweb.perl @@ -571,12 +571,17 @@ sub esc_url { } # replace invalid utf8 character with SUBSTITUTION sequence -sub esc_html { +sub esc_html ($;%) { my $str = shift; + my %opts = @_; + $str = to_utf8($str); $str = escapeHTML($str); $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file) $str =~ s/\033/^[/g; # "escape" ESCAPE (\e) character (e.g. commit 20a3847d8a5032ce41f90dcc68abfb36e6fee9b1) + if ($opts{'-nbsp'}) { + $str =~ s/ / /g; + } return $str; } @@ -801,7 +806,7 @@ sub format_diff_line { $diff_class = " incomplete"; } $line = untabify($line); - return "
" . esc_html($line) . "
\n"; + return "
" . esc_html($line, -nbsp=>1) . "
\n"; } ## ---------------------------------------------------------------------- @@ -3037,7 +3042,7 @@ sub git_blob { $nr++; $line = untabify($line); printf "
%4i %s
\n", - $nr, $nr, $nr, esc_html($line); + $nr, $nr, $nr, esc_html($line, -nbsp=>1); } close $fd or print "Reading blob failed.\n";