gitweb: Add new option -nohtml to quot_xxx subroutines
Add support for new option -nohtml to quot_cec and quot_upr subroutines, to have output not wrapped in HTML tags. This makes those subroutines suitable to quoting attributes values, and for plain text output quoting. Currently this API is not used yet. While at it fix whitespace, and use ';' as delimiter, not separator. The option to not wrap quot_cec output in HTML tag were proposed originally in patch: "Don't open a XML tag while another one is already open" Message-ID: <20080216191628.GK30676@schiele.dyndns.org> by Robert Schiele. Originally the parameter was named '-notag', was also supportted by esc_html (but not esc_path) which passed it down to quot_cec. Mentioned patch was meant to fix the bug Martin Koegler reported in his mail "Invalid html output repo.or.cz (alt-git.git)" Message-ID: <20080216130037.GA14571@auto.tuwien.ac.at> which was fixed in different way (do not use esc_html to escape and quote HTML attributes). Signed-off-by: Robert Schiele <rschiele@gmail.com> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
850b90a51d
commit
c84c483ffd
@ -753,6 +753,7 @@ sub esc_path {
|
|||||||
# Make control characters "printable", using character escape codes (CEC)
|
# Make control characters "printable", using character escape codes (CEC)
|
||||||
sub quot_cec {
|
sub quot_cec {
|
||||||
my $cntrl = shift;
|
my $cntrl = shift;
|
||||||
|
my %opts = @_;
|
||||||
my %es = ( # character escape codes, aka escape sequences
|
my %es = ( # character escape codes, aka escape sequences
|
||||||
"\t" => '\t', # tab (HT)
|
"\t" => '\t', # tab (HT)
|
||||||
"\n" => '\n', # line feed (LF)
|
"\n" => '\n', # line feed (LF)
|
||||||
@ -767,16 +768,26 @@ sub quot_cec {
|
|||||||
my $chr = ( (exists $es{$cntrl})
|
my $chr = ( (exists $es{$cntrl})
|
||||||
? $es{$cntrl}
|
? $es{$cntrl}
|
||||||
: sprintf('\%03o', ord($cntrl)) );
|
: sprintf('\%03o', ord($cntrl)) );
|
||||||
|
if ($opts{-nohtml}) {
|
||||||
|
return $chr;
|
||||||
|
} else {
|
||||||
return "<span class=\"cntrl\">$chr</span>";
|
return "<span class=\"cntrl\">$chr</span>";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Alternatively use unicode control pictures codepoints,
|
# Alternatively use unicode control pictures codepoints,
|
||||||
# Unicode "printable representation" (PR)
|
# Unicode "printable representation" (PR)
|
||||||
sub quot_upr {
|
sub quot_upr {
|
||||||
my $cntrl = shift;
|
my $cntrl = shift;
|
||||||
|
my %opts = @_;
|
||||||
|
|
||||||
my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
|
my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
|
||||||
|
if ($opts{-nohtml}) {
|
||||||
|
return $chr;
|
||||||
|
} else {
|
||||||
return "<span class=\"cntrl\">$chr</span>";
|
return "<span class=\"cntrl\">$chr</span>";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# git may return quoted and escaped filenames
|
# git may return quoted and escaped filenames
|
||||||
sub unquote {
|
sub unquote {
|
||||||
@ -800,7 +811,7 @@ sub unquote {
|
|||||||
return chr(oct($seq));
|
return chr(oct($seq));
|
||||||
} elsif (exists $es{$seq}) {
|
} elsif (exists $es{$seq}) {
|
||||||
# C escape sequence, aka character escape code
|
# C escape sequence, aka character escape code
|
||||||
return $es{$seq}
|
return $es{$seq};
|
||||||
}
|
}
|
||||||
# quoted ordinary character
|
# quoted ordinary character
|
||||||
return $seq;
|
return $seq;
|
||||||
|
Loading…
Reference in New Issue
Block a user