+sub pad_link ($$;$) {
+ my ($mid, $level, $s) = @_;
+ $s ||= '...';
+ my $id = id_compress($mid, 1);
+ (' 'x19).indent_for($level).th_pfx($level)."<a\nhref=#r$id>($s)</a>\n";
+}
+
+sub _th_index_lite {
+ my ($mid_raw, $irt, $id, $ctx) = @_;
+ my $rv = '';
+ my $mapping = $ctx->{mapping} or return $rv;
+ my $pad = ' ';
+ # map = [children, attr, node, idx, level]
+ my $map = $mapping->{$mid_raw};
+ my $nr_c = scalar @{$map->[0]};
+ my $nr_s = 0;
+ my $level = $map->[4];
+ my $idx = $map->[3];
+ my $irt_map = $mapping->{$irt} if defined $irt;
+ if (defined $irt_map) {
+ my $siblings = $irt_map->[0];
+ $nr_s = scalar(@$siblings) - 1;
+ $rv .= $pad . $irt_map->[1];
+ if ($idx > 0) {
+ my $prev = $siblings->[$idx - 1];
+ my $pmid = $prev->messageid;
+ if ($idx > 2) {
+ my $s = ($idx - 1). ' preceding siblings ...';
+ $rv .= pad_link($pmid, $level, $s);
+ } elsif ($idx == 2) {
+ my $ppmid = $siblings->[0]->messageid;
+ $rv .= $pad . $mapping->{$ppmid}->[1];
+ }
+ $rv .= $pad . $mapping->{$pmid}->[1];
+ }
+ }
+ my $s_s = nr_to_s($nr_s, 'sibling', 'siblings');
+ my $s_c = nr_to_s($nr_c, 'reply', 'replies');
+ my $this = $map->[1];
+ $this =~ s!\n\z!</b>\n!s;
+ $this =~ s!<a\nhref.*</a> !!s; # no point in duplicating subject
+ $this =~ s!<a\nhref=[^>]+>([^<]+)</a>!$1!s; # no point linking to self
+ $rv .= "<b>@ $this";
+ my $node = $map->[2];
+ if (my $child = $node->child) {
+ my $cmid = $child->messageid;
+ $rv .= $pad . $mapping->{$cmid}->[1];
+ if ($nr_c > 2) {
+ my $s = ($nr_c - 1). ' more replies';
+ $rv .= pad_link($cmid, $level + 1, $s);
+ } elsif (my $cn = $child->next) {
+ $rv .= $pad . $mapping->{$cn->messageid}->[1];
+ }
+ }
+ if (my $next = $node->next) {
+ my $nmid = $next->messageid;
+ $rv .= $pad . $mapping->{$nmid}->[1];
+ my $nnext = $nr_s - $idx;
+ if ($nnext > 2) {
+ my $s = ($nnext - 1).' subsequent siblings';
+ $rv .= pad_link($nmid, $level, $s);
+ } elsif (my $nn = $next->next) {
+ $rv .= $pad . $mapping->{$nn->messageid}->[1];
+ }
+ }
+ $rv .= $pad ."<a\nhref=#r$id>$s_s, $s_c; $ctx->{s_nr}</a>\n";