-sub diff_before_or_after ($$$) {
- my ($dst, $ctx, $x) = @_;
- my $linkify = $ctx->{-linkify};
- for my $y (split(/(^---\n)/sm, $$x)) {
- if ($y =~ /\A---\n\z/s) {
- $$dst .= "---\n"; # all HTML is "\r\n" => "\n"
- } elsif ($y =~ /^ [0-9]+ files? changed, /sm) {
- # ok, looks like a diffstat, go line-by-line:
- for my $l (split(/^/m, $y)) {
- if ($l =~ /^ (.+)( +\| .*\z)/s) {
- anchor0($dst, $ctx, $1, $2) and next;
- }
- $$dst .= $linkify->to_html($l);
- }
- } else { # commit message, notes, etc
- $$dst .= $linkify->to_html($y);
+sub diff_before_or_after ($$) {
+ my ($ctx, $x) = @_;
+ if (exists $ctx->{-anchors} && $$x =~ /\A(.*?) # likely "---\n" # \$1
+ # diffstat lines:
+ ((?:^\x20(?:[^\n]+?)(?:\x20+\|\x20[^\n]*\n))+)
+ (\x20[0-9]+\x20files?\x20)changed,([^\n]+\n)
+ (.*?)\z/msx) { # notes, commit message, etc
+ my @x = ($5, $4, $3, $2, $1);
+ undef $$x;
+ my $lnk = $ctx->{-linkify};
+ my $zfh = $ctx->{zfh};
+ print $zfh $lnk->to_html(pop @x); # $1 uninteresting prefix
+ for my $l (split(/^/m, pop(@x))) { # $2 per-file stat lines
+ $l =~ /^ (.+)( +\| .*\z)/s and
+ anchor0($ctx, $1, $2) and next;
+ print $zfh $lnk->to_html($l);