From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.4 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, RP_MATCHES_RCVD shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 121C31F8B6 for ; Thu, 20 Aug 2015 02:57:24 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/11] use tables for rendering comment nesting Date: Thu, 20 Aug 2015 02:57:15 +0000 Message-Id: <1440039443-27052-3-git-send-email-e@80x24.org> In-Reply-To: <1440039443-27052-1-git-send-email-e@80x24.org> References: <1440039443-27052-1-git-send-email-e@80x24.org> List-Id: This is more space efficient since we don't need to place padding bytes in front of every line. While this unfortunately does not render well on lynx; w3m, links, elinks can all render tables sanely. Tables are also superior for long lines which require wrapping inside
 containers.
---
 lib/PublicInbox/Feed.pm |  7 +++----
 lib/PublicInbox/View.pm | 43 ++++++++++++++++++-------------------------
 2 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 0b7ef7f..8bfd19e 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -12,7 +12,6 @@ use PublicInbox::View;
 use constant {
 	DATEFMT => '%Y-%m-%dT%H:%M:%SZ', # atom standard
 	MAX_PER_PAGE => 25, # this needs to be tunable
-	PRE_WRAP => "",
 };
 
 # main function
@@ -60,7 +59,7 @@ sub generate_html_index {
 	my $html = "$title" .
 		'{atomurl} . "\"\ntype=\"application/atom+xml\"/>" .
-		'' . PRE_WRAP;
+		'';
 
 	my $state;
 	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
@@ -80,9 +79,9 @@ sub generate_html_index {
 	if ($footer) {
 		my $list_footer = $ctx->{footer};
 		$footer .= "\n" . $list_footer if $list_footer;
-		$footer = "
" . PRE_WRAP . "$footer
"; + $footer = "
$footer
"; } - $html . "$footer"; + $html .= "$footer"; } # private subs diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 4a8e54a..800c1a2 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -33,8 +33,9 @@ sub msg_html { } headers_to_html_header($mime, $full_pfx, $srch) . multipart_text_as_html($mime, $full_pfx) . - '
' . PRE_WRAP . - html_footer($mime, 1, $full_pfx, $srch) . $footer . + '
' .
+		html_footer($mime, 1, $full_pfx, $srch) .
+		$footer .
 		'
'; } @@ -51,7 +52,6 @@ sub index_entry { my ($srch, $seen, $first_commit) = @$state; my $midx = $state->[3]++; my ($prev, $next) = ($midx - 1, $midx + 1); - my $rv = ''; my $part_nr = 0; my $enc_msg = enc_for($mime->header("Content-Type")); my $subj = $mime->header('Subject'); @@ -69,15 +69,9 @@ sub index_entry { $from = PublicInbox::Hval->new_oneline($from)->as_html; $subj = PublicInbox::Hval->new_oneline($subj)->as_html; - my $pfx = (' ' x $level); my $root_anchor = $seen->{root_anchor}; - my $path; my $more = 'permalink'; - if ($root_anchor) { - $path = '../'; - } else { - $path = ''; - } + my $path = $root_anchor ? '../' : ''; my $href = $mid->as_href; my $irt = $header_obj->header_raw('In-Reply-To'); my ($anchor_idx, $anchor, $t_anchor); @@ -88,7 +82,6 @@ sub index_entry { } else { $t_anchor = ''; } - if (defined $srch) { $subj = "$subj"; } @@ -103,7 +96,12 @@ sub index_entry { my $fmt = '%Y-%m-%d %H:%M'; $ts = POSIX::strftime($fmt, gmtime($ts)); - $rv .= "$pfx$subj\n$pfx"; + my $rv = ""; + if ($level) { + $rv .= '
' . ('  ' x $level) . '
'; + } + $rv .= '' . PRE_WRAP; + $rv .= "$subj\n"; $rv .= "- by $from @ $ts UTC - "; $rv .= "next"; if ($prev >= 0) { @@ -115,13 +113,12 @@ sub index_entry { my $fhref = "${path}f/$href.html"; # scan through all parts, looking for displayable text $mime->walk_parts(sub { - $rv .= index_walk($_[0], $pfx, $enc_msg, $part_nr, $fhref, - \$more); + $rv .= index_walk($_[0], $enc_msg, $part_nr, $fhref, \$more); $part_nr++; }); $mime->body_set(''); - $rv .= "\n$pfx$more "; + $rv .= "\n$more "; my $txt = "${path}m/$href.txt"; $rv .= "raw "; $rv .= html_footer($mime, 0); @@ -141,7 +138,7 @@ sub index_entry { "threadlink"; } - $rv . "\n\n"; + $rv .= ''; } sub thread_html { @@ -168,7 +165,7 @@ sub thread_html { } $next .= ", back to index\n"; - $rv .= "
" . PRE_WRAP . $next . $foot . ""; + $rv .= "
" . PRE_WRAP . $next . $foot . ""; } sub subject_path_html { @@ -188,13 +185,13 @@ sub subject_path_html { my $final_anchor = $state->[3]; my $next = "end of thread\n"; - $rv .= "
" . PRE_WRAP . $next . $foot . ""; + $rv .= "
" . PRE_WRAP . $next . $foot . ""; } # only private functions below. sub index_walk { - my ($part, $pfx, $enc_msg, $part_nr, $fhref, $more) = @_; + my ($part, $enc_msg, $part_nr, $fhref, $more) = @_; my $rv = ''; return $rv if $part->subparts; # walk_parts already recurses my $ct = $part->content_type; @@ -207,7 +204,7 @@ sub index_walk { if ($part_nr > 0) { my $fn = $part->filename; defined($fn) or $fn = "part #" . ($part_nr + 1); - $rv .= $pfx . add_filename_line($enc->decode($fn)); + $rv .= add_filename_line($enc->decode($fn)); } my $s = add_text_body_short($enc, $part, $part_nr, $fhref); @@ -224,9 +221,6 @@ sub index_walk { $s =~ s/\s+\z//s; if (length $s) { - # add prefix: - $s =~ s/^/$pfx/sgm; - # kill per-line trailing whitespace $s =~ s/[ \t]+$//sgm; @@ -549,8 +543,7 @@ sub thread_html_head { my ($mime) = @_; my $s = PublicInbox::Hval->new_oneline($mime->header('Subject')); $s = $s->as_html; - "$s" . PRE_WRAP - + "$s"; } sub thread_entry { -- EW