From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 03/11] use tables for rendering comment nesting
Date: Thu, 20 Aug 2015 02:57:15 +0000 [thread overview]
Message-ID: <1440039443-27052-3-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1440039443-27052-1-git-send-email-e@80x24.org>
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 <pre> 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 => "<pre\nstyle=\"white-space:pre-wrap\">",
};
# main function
@@ -60,7 +59,7 @@ sub generate_html_index {
my $html = "<html><head><title>$title</title>" .
'<link rel="alternate" title="Atom feed"' . "\nhref=\"" .
$feed_opts->{atomurl} . "\"\ntype=\"application/atom+xml\"/>" .
- '</head><body>' . PRE_WRAP;
+ '</head><body>';
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 = "<hr />" . PRE_WRAP . "$footer</pre>";
+ $footer = "<hr /><pre>$footer</pre>";
}
- $html . "</pre>$footer</body></html>";
+ $html .= "$footer</body></html>";
}
# 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><hr />' . PRE_WRAP .
- html_footer($mime, 1, $full_pfx, $srch) . $footer .
+ '</pre><hr /><pre>' .
+ html_footer($mime, 1, $full_pfx, $srch) .
+ $footer .
'</pre></body></html>';
}
@@ -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 = "<a\nhref=\"${path}t/$href.html#u\">$subj</a>";
}
@@ -103,7 +96,12 @@ sub index_entry {
my $fmt = '%Y-%m-%d %H:%M';
$ts = POSIX::strftime($fmt, gmtime($ts));
- $rv .= "$pfx<b\nid=\"$id\">$subj</b>\n$pfx";
+ my $rv = "<table\nsummary=l$level><tr>";
+ if ($level) {
+ $rv .= '<td><pre>' . (' ' x $level) . '</pre></td>';
+ }
+ $rv .= '<td>' . PRE_WRAP;
+ $rv .= "<b\nid=\"$id\">$subj</b>\n";
$rv .= "- by $from @ $ts UTC - ";
$rv .= "<a\nid=\"s$midx\"\nhref=\"#s$next\">next</a>";
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<a\nhref=\"$mhref\">$more</a> ";
+ $rv .= "\n<a\nhref=\"$mhref\">$more</a> ";
my $txt = "${path}m/$href.txt";
$rv .= "<a\nhref=\"$txt\">raw</a> ";
$rv .= html_footer($mime, 0);
@@ -141,7 +138,7 @@ sub index_entry {
"threadlink</a>";
}
- $rv . "\n\n";
+ $rv .= '</pre></td></tr></table>';
}
sub thread_html {
@@ -168,7 +165,7 @@ sub thread_html {
}
$next .= "</a>, back to <a\nhref=\"../\">index</a>\n";
- $rv .= "</pre><hr />" . PRE_WRAP . $next . $foot . "</pre>";
+ $rv .= "<hr />" . PRE_WRAP . $next . $foot . "</pre>";
}
sub subject_path_html {
@@ -188,13 +185,13 @@ sub subject_path_html {
my $final_anchor = $state->[3];
my $next = "<a\nid=\"s$final_anchor\">end of thread</a>\n";
- $rv .= "</pre><hr />" . PRE_WRAP . $next . $foot . "</pre>";
+ $rv .= "<hr />" . PRE_WRAP . $next . $foot . "</pre>";
}
# 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;
- "<html><head><title>$s</title></head><body>" . PRE_WRAP
-
+ "<html><head><title>$s</title></head><body>";
}
sub thread_entry {
--
EW
next prev parent reply other threads:[~2015-08-20 2:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-20 2:57 [PATCH 01/11] feed: remove threading from index Eric Wong
2015-08-20 2:57 ` [PATCH 02/11] feed: move timestamp parsing to view Eric Wong
2015-08-20 2:57 ` Eric Wong [this message]
2015-08-20 2:57 ` [PATCH 04/11] view: avoid nesting <a> tags from auto-linkification Eric Wong
2015-08-20 2:57 ` [PATCH 05/11] index: simplify main landing page if search-enabled Eric Wong
2015-08-20 2:57 ` [PATCH 06/11] search: avoid needless decode Eric Wong
2015-08-20 2:57 ` [PATCH 07/11] search: reject ghosts in all cases Eric Wong
2015-08-20 2:57 ` [PATCH 08/11] view: reduce memory usage when displaying large threads Eric Wong
2015-08-20 2:57 ` [PATCH 09/11] search: bump schema version to 5 for subject_path Eric Wong
2015-08-20 2:57 ` [PATCH 10/11] index: layout fix + title and Atom feed links at top Eric Wong
2015-08-20 2:57 ` [PATCH 11/11] view: do not fold top-level messages in thread Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440039443-27052-3-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).