gitweb: Pass esc_html_hl_regions() options to esc_html()
With this change, esc_html_hl_regions() accepts options and passes them down to esc_html(). This may be needed if a caller wants to pass -nbsp=>1 to esc_html(). The idea and implementation example of this change was described in 337da8d2 (gitweb: Introduce esc_html_match_hl and esc_html_hl_regions, 2012-02-27). While other suggestions may be more useful in some cases, there is no need to implement them at the moment. The esc_html_hl_regions() interface may be changed later if it's needed. [mk: extracted from larger patch and wrote commit message] Signed-off-by: Jakub Narębski <jnareb@gmail.com> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jakub Narębski committed
Apr 11, 2012 at 23:18 UTC
9768a9d884ee293548c0435df7645fd82d8d942e
1 file changed
+7
-4
gitweb/gitweb.perl
+7
-4
@@ -1732,7 +1732,9 @@ sub chop_and_escape_str {
1732
# '<span class="mark">foo</span>bar'
1733
sub esc_html_hl_regions {
1734
my ($str, $css_class, @sel) = @_;
1735
- return esc_html($str) unless @sel;
1735
+ my %opts = grep { ref($_) ne 'ARRAY' } @sel;
1736
+ @sel = grep { ref($_) eq 'ARRAY' } @sel;
1737
+ return esc_html($str, %opts) unless @sel;
1738
1739
my $out = '';
1740
my $pos = 0;
@@ -1743,15 +1745,16 @@ sub esc_html_hl_regions {
1745
# Don't create empty <span> elements.
1746
next if $end <= $begin;
1747
1746
- my $escaped = esc_html(substr($str, $begin, $end - $begin));
1748
+ my $escaped = esc_html(substr($str, $begin, $end - $begin),
1749
+ %opts);
1750
1748
- $out .= esc_html(substr($str, $pos, $begin - $pos))
1751
+ $out .= esc_html(substr($str, $pos, $begin - $pos), %opts)
1752
if ($begin - $pos > 0);
1753
$out .= $cgi->span({-class => $css_class}, $escaped);
1754
1755
$pos = $end;
1756
}
1754
- $out .= esc_html(substr($str, $pos))
1757
+ $out .= esc_html(substr($str, $pos), %opts)
1758
if ($pos < length($str));
1759
1760
return $out;