unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] view: reduce empty <a>, use "id" instead of "name" attributes
@ 2015-07-06 20:54 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-07-06 20:54 UTC (permalink / raw)
  To: meta

This is probably more compliant, and saves us a few bytes
on the uncompressed HTML.
---
 lib/PublicInbox/View.pm | 18 +++++++-----------
 t/view.t                |  2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 3695bb2..bc4c7ac 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -54,8 +54,8 @@ sub index_entry {
 	my $header_obj = $mime->header_obj;
 
 	my $mid_raw = $header_obj->header_raw('Message-ID');
-	my $name = anchor_for($mid_raw);
-	$seen->{$name} = "#$name"; # save the anchor for later
+	my $id = anchor_for($mid_raw);
+	$seen->{$id} = "#$id"; # save the anchor for later
 
 	my $mid = PublicInbox::Hval->new_msgid($mid_raw);
 	my $from = PublicInbox::Hval->new_oneline($mime->header('From'))->raw;
@@ -78,13 +78,9 @@ sub index_entry {
 	}
 	$ts = POSIX::strftime($fmt, gmtime($ts));
 
-	$rv .= "$pfx<a\nname=\"$name\"></a>" .
-		"<a\nname=\"s$midx\"></a>" .
-		"<b>$subj</b>\n$pfx";
-
+	$rv .= "$pfx<b\nid=\"$id\">$subj</b>\n$pfx";
 	$rv .= "- by $from @ $ts - ";
-
-	$rv .= "<a\nhref=\"#s$next\">next</a>";
+	$rv .= "<a\nid=\"s$midx\"\nhref=\"#s$next\">next</a>";
 	if ($prev >= 0) {
 		$rv .= "/<a\nhref=\"#s$prev\">prev</a>";
 	}
@@ -153,7 +149,7 @@ sub index_entry {
 		}
 		$rv .= " <a\nhref=\"$anchor\">parent</a>";
 	}
-	$rv .= " <a\nhref=\"?r=$first#$name\">threadlink</a>";
+	$rv .= " <a\nhref=\"?r=$first#$id\">threadlink</a>";
 
 	$rv . "\n\n";
 }
@@ -269,7 +265,7 @@ sub add_text_body_full {
 		my $cur = $1;
 		my @lines = split(/\n/, $cur);
 		if (@lines > MAX_INLINE_QUOTED) {
-			"<a\nname=q${part_nr}_" . $n++ . ">$cur</a>";
+			"<a\nid=q${part_nr}_" . $n++ . ">$cur</a>";
 		} else {
 			$cur;
 		}
@@ -382,7 +378,7 @@ sub anchor_for {
 	my ($msgid) = @_;
 	$msgid =~ s/\A\s*<?//;
 	$msgid =~ s/>?\s*\z//;
-	Digest::SHA::sha1_hex($msgid);
+	'm' . Digest::SHA::sha1_hex($msgid);
 }
 
 1;
diff --git a/t/view.t b/t/view.t
index 1851793..63de49b 100644
--- a/t/view.t
+++ b/t/view.t
@@ -47,7 +47,7 @@ EOF
 	like($html, qr!<a\nhref="\.\./m/hello%40!s, "MID link present");
 	like($html, qr/hello world\b/, "body present");
 	like($html, qr/&gt; keep this inline/, "short quoted text is inline");
-	like($html, qr/<a\nname=[^>]+>&gt; Long and wordy/,
+	like($html, qr/<a\nid=[^>]+>&gt; Long and wordy/,
 		"long quoted text is anchored");
 
 	# short page
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-07-06 20:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-06 20:54 [PATCH] view: reduce empty <a>, use "id" instead of "name" attributes Eric Wong

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).