We use the same idiom in many places for doing two-step
linkification and HTML escaping. Get rid of an outdated
comment in flush_quote while we're at it.
+sub to_html { linkify_2($_[0], ascii_html(linkify_1(@_))) }
+
sub flush_quote {
my ($s, $l, $quot) = @_;
sub flush_quote {
my ($s, $l, $quot) = @_;
- # show everything in the full version with anchor from
- # short version (see above)
- my $rv = $l->linkify_1($$quot);
+ my $rv = $l->to_html($$quot);
# we use a <span> here to allow users to specify their own
# color for quoted text
# we use a <span> here to allow users to specify their own
# color for quoted text
- $rv = $l->linkify_2(ascii_html($rv));
$$quot = undef;
$$s .= qq(<span\nclass="q">) . $rv . '</span>'
}
$$quot = undef;
$$s .= qq(<span\nclass="q">) . $rv . '</span>'
}
flush_diff($rv, $ctx, $l);
} else {
# regular lines, OK
flush_diff($rv, $ctx, $l);
} else {
# regular lines, OK
- $l->linkify_1($cur);
- $$rv .= $l->linkify_2(ascii_html($cur));
+ $$rv .= $l->to_html($cur);
# cf. git diff.c :: get_compact_summary
my $DIFFSTAT_COMMENT = qr/\((?:new|gone|(?:(?:new|mode) [\+\-][lx]))\)/;
# cf. git diff.c :: get_compact_summary
my $DIFFSTAT_COMMENT = qr/\((?:new|gone|(?:(?:new|mode) [\+\-][lx]))\)/;
-sub to_html ($$) {
- $_[0]->linkify_1($_[1]);
- $_[0]->linkify_2(ascii_html($_[1]));
-}
-
# link to line numbers in blobs
sub diff_hunk ($$$$) {
my ($dctx, $spfx, $ca, $cb) = @_;
# link to line numbers in blobs
sub diff_hunk ($$$$) {
my ($dctx, $spfx, $ca, $cb) = @_;
my $spaces = ($orig =~ s/( +)\z//) ? $1 : '';
$$dst .= " <a\nid=i$attr\nhref=#$attr>" .
ascii_html($orig) . '</a>' . $spaces .
my $spaces = ($orig =~ s/( +)\z//) ? $1 : '';
$$dst .= " <a\nid=i$attr\nhref=#$attr>" .
ascii_html($orig) . '</a>' . $spaces .
- to_html($linkify, $rest);
+ $linkify->to_html($rest);
sub anchor1 ($$$$$) {
my ($dst, $ctx, $linkify, $pb, $s) = @_;
my $attr = to_attr($ctx->{-apfx}.$pb) or return;
sub anchor1 ($$$$$) {
my ($dst, $ctx, $linkify, $pb, $s) = @_;
my $attr = to_attr($ctx->{-apfx}.$pb) or return;
- my $line = to_html($linkify, $s);
+ my $line = $linkify->to_html($s);
my $ok = delete $ctx->{-anchors}->{$attr};
my $ok = delete $ctx->{-anchors}->{$attr};
} elsif ($state2class[$state]) {
to_state($dst, $state, DSTATE_CTX);
}
} elsif ($state2class[$state]) {
to_state($dst, $state, DSTATE_CTX);
}
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
} elsif ($s =~ /^-- $/) { # email signature begins
$state == DSTATE_INIT or
to_state($dst, $state, DSTATE_INIT);
} elsif ($s =~ /^-- $/) { # email signature begins
$state == DSTATE_INIT or
to_state($dst, $state, DSTATE_INIT);
uri_escape_utf8($pa, UNSAFE);
}
anchor1($dst, $ctx, $linkify, $pb, $s) and next;
uri_escape_utf8($pa, UNSAFE);
}
anchor1($dst, $ctx, $linkify, $pb, $s) and next;
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
} elsif ($s =~ s/^(index $OID_NULL\.\.)($OID_BLOB)\b//o) {
$$dst .= $1 . oid($dctx, $spfx, $2);
$dctx = { Q => '' };
} elsif ($s =~ s/^(index $OID_NULL\.\.)($OID_BLOB)\b//o) {
$$dst .= $1 . oid($dctx, $spfx, $2);
$dctx = { Q => '' };
- $$dst .= to_html($linkify, $s) ;
+ $$dst .= $linkify->to_html($s) ;
} elsif ($s =~ s/^index ($OID_BLOB)(\.\.$OID_NULL)\b//o) {
$$dst .= 'index ' . oid($dctx, $spfx, $1) . $2;
$dctx = { Q => '' };
} elsif ($s =~ s/^index ($OID_BLOB)(\.\.$OID_NULL)\b//o) {
$$dst .= 'index ' . oid($dctx, $spfx, $1) . $2;
$dctx = { Q => '' };
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
} elsif ($s =~ /^index ($OID_BLOB)\.\.($OID_BLOB)/o) {
$dctx->{oid_a} = $1;
$dctx->{oid_b} = $2;
} elsif ($s =~ /^index ($OID_BLOB)\.\.($OID_BLOB)/o) {
$dctx->{oid_a} = $1;
$dctx->{oid_b} = $2;
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
} elsif ($s =~ s/^@@ (\S+) (\S+) @@//) {
$$dst .= '</span>' if $state2class[$state];
$$dst .= qq(<span\nclass="hunk">);
$$dst .= diff_hunk($dctx, $spfx, $1, $2);
$$dst .= '</span>';
$state = DSTATE_CTX;
} elsif ($s =~ s/^@@ (\S+) (\S+) @@//) {
$$dst .= '</span>' if $state2class[$state];
$$dst .= qq(<span\nclass="hunk">);
$$dst .= diff_hunk($dctx, $spfx, $1, $2);
$$dst .= '</span>';
$state = DSTATE_CTX;
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
} elsif ($s =~ m!^--- (?:$PATH_A)!o ||
$s =~ m!^\+{3} (?:$PATH_B)!o) {
# color only (no oid link) if missing dctx->{oid_*}
$state <= DSTATE_STAT and
to_state($dst, $state, DSTATE_HEAD);
} elsif ($s =~ m!^--- (?:$PATH_A)!o ||
$s =~ m!^\+{3} (?:$PATH_B)!o) {
# color only (no oid link) if missing dctx->{oid_*}
$state <= DSTATE_STAT and
to_state($dst, $state, DSTATE_HEAD);
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
} elsif ($s =~ /^\+/) {
if ($state != DSTATE_ADD && $state > DSTATE_STAT) {
to_state($dst, $state, DSTATE_ADD);
}
} elsif ($s =~ /^\+/) {
if ($state != DSTATE_ADD && $state > DSTATE_STAT) {
to_state($dst, $state, DSTATE_ADD);
}
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
} elsif ($s =~ /^-/) {
if ($state != DSTATE_DEL && $state > DSTATE_STAT) {
to_state($dst, $state, DSTATE_DEL);
}
} elsif ($s =~ /^-/) {
if ($state != DSTATE_DEL && $state > DSTATE_STAT) {
to_state($dst, $state, DSTATE_DEL);
}
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
# ignore the following lines in headers:
} elsif ($s =~ /^(?:dis)similarity index/ ||
$s =~ /^(?:old|new) mode/ ||
$s =~ /^(?:deleted|new) file mode/ ||
$s =~ /^(?:copy|rename) (?:from|to) / ||
$s =~ /^(?:dis)?similarity index /) {
# ignore the following lines in headers:
} elsif ($s =~ /^(?:dis)similarity index/ ||
$s =~ /^(?:old|new) mode/ ||
$s =~ /^(?:deleted|new) file mode/ ||
$s =~ /^(?:copy|rename) (?:from|to) / ||
$s =~ /^(?:dis)?similarity index /) {
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
} else {
$state <= DSTATE_STAT or
to_state($dst, $state, DSTATE_INIT);
} else {
$state <= DSTATE_STAT or
to_state($dst, $state, DSTATE_INIT);
- $$dst .= to_html($linkify, $s);
+ $$dst .= $linkify->to_html($s);
}
my $l = PublicInbox::Linkify->new;
utf8::decode($$bref);
}
my $l = PublicInbox::Linkify->new;
utf8::decode($$bref);
- $l->linkify_1($$bref);
- $$bref = '<pre>'. $l->linkify_2(ascii_html($$bref));
+ $$bref = '<pre>'. $l->to_html($$bref);
$$bref .= '</pre><hr>' . $$logref;
html_page($ctx, 200, $bref);
}
$$bref .= '</pre><hr>' . $$logref;
html_page($ctx, 200, $bref);
}
my $ref = ref($res);
my $l = PublicInbox::Linkify->new;
my $ref = ref($res);
my $l = PublicInbox::Linkify->new;
$log = '<pre>debug log:</pre><hr /><pre>' .
$log = '<pre>debug log:</pre><hr /><pre>' .
- $l->linkify_2(ascii_html($log)) . '</pre>';
+ $l->to_html($log) . '</pre>';
$res or return html_page($ctx, 404, \$log);
$ref eq 'ARRAY' or return html_page($ctx, 500, \$log);
$res or return html_page($ctx, 404, \$log);
$ref eq 'ARRAY' or return html_page($ctx, 500, \$log);
my $tmp = join("\n", map { ibx_entry(@$_, $env) } @$list);
my $l = PublicInbox::Linkify->new;
my $tmp = join("\n", map { ibx_entry(@$_, $env) } @$list);
my $l = PublicInbox::Linkify->new;
- $l->linkify_1($tmp);
- $out = '<pre>'.$l->linkify_2(ascii_html($tmp)).'</pre><hr>';
+ $out = '<pre>'.$l->to_html($tmp).'</pre><hr>';
}
$out = "<html><head><title>$title</title></head><body>" . $out;
$out .= '<pre>'. PublicInbox::WwwStream::code_footer($env) .
}
$out = "<html><head><title>$title</title></head><body>" . $out;
$out .= '<pre>'. PublicInbox::WwwStream::code_footer($env) .