unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] view: favor whitespace wrap in <head>
Date: Fri, 25 Dec 2015 12:06:30 +0000	[thread overview]
Message-ID: <20151225120630.14664-2-e@80x24.org> (raw)
In-Reply-To: <20151225120630.14664-1-e@80x24.org>

If we bite the bullet and rely on inline CSS, we might as well
only specify it once per page instead of inline in every <pre>
tag which may handle UGC.  So this actually saves us a small
amount of bandwith on most pages which have multiple <pre>
start tags.
---
 lib/PublicInbox/Feed.pm       |  8 ++++----
 lib/PublicInbox/Hval.pm       |  3 ++-
 lib/PublicInbox/SearchView.pm |  2 +-
 lib/PublicInbox/View.pm       | 18 ++++++++++--------
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 150bea0..7ebc050 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -128,18 +128,18 @@ sub emit_html_index {
 	my $top = "<b>$title</b> (<a\nhref=\"$atom_url\">Atom feed</a>)";
 
 	if ($srch) {
-		$top = qq{<form\naction=""><tt>$top} .
+		$top = qq{<form\naction=""><pre>$top} .
 			  qq{ <input\nname=q\ntype=text />} .
 			  qq{<input\ntype=submit\nvalue=search />} .
-			  qq{</tt></form>} .
-			  PublicInbox::Hval::PRE;
+			  q{</pre></form><pre>}
 	} else {
-		$top = PublicInbox::Hval::PRE . $top . "\n";
+		$top = '<pre>' . $top . "\n";
 	}
 
 	$fh->write("<html><head><title>$title</title>" .
 		   "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
 		   "href=\"$atom_url\"\ntype=\"application/atom+xml\"/>" .
+		   PublicInbox::Hval::STYLE .
 		   "</head><body>$top");
 
 	# if the 'r' query parameter is given, it is a legacy permalink
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index e0b85c6..5a86935 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -13,7 +13,8 @@ use PublicInbox::MID qw/mid_clean/;
 # for user-generated content (UGC) which may have excessively long lines
 # and screw up rendering on some browsers.  This is the only CSS style
 # feature we use.
-use constant PRE => "<pre\nstyle=\"white-space:pre-wrap\">";
+use constant STYLE => '<style>pre{white-space:pre-wrap}</style>';
+use constant PRE => "<pre\nstyle=\"white-space:pre-wrap\">"; # legacy
 
 my $enc_ascii = find_encoding('us-ascii');
 
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index fec4f39..5b15e0d 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -32,7 +32,7 @@ sub sres_top_html {
 		$total = $mset->get_matches_estimated;
 	};
 	my $err = $@;
-	my $res = html_start($q, $ctx) . PublicInbox::Hval::PRE;
+	my $res = html_start($q, $ctx) . '<pre>'
 	if ($err) {
 		$code = 400;
 		$res .= err_txt($err) . "</pre><hr /><pre>" . foot($ctx);
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 523d27f..7603c51 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -38,7 +38,7 @@ sub msg_html {
 	}
 	headers_to_html_header($mime, $full_pfx, $ctx) .
 		multipart_text_as_html($mime, $full_pfx) .
-		'</pre><hr />' . PublicInbox::Hval::PRE .
+		'</pre><hr /><pre>' .
 		html_footer($mime, 1, $full_pfx, $ctx) .
 		$footer .
 		'</pre></body></html>';
@@ -47,6 +47,7 @@ sub msg_html {
 sub feed_entry {
 	my ($class, $mime, $full_pfx) = @_;
 
+	# no <head> here for <style>...
 	PublicInbox::Hval::PRE .
 		multipart_text_as_html($mime, $full_pfx) . '</pre>';
 }
@@ -107,7 +108,7 @@ sub index_entry {
 	if ($level) {
 		$rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
 	}
-	$rv .= "<td\nid=s$midx>" . PublicInbox::Hval::PRE;
+	$rv .= "<td\nid=s$midx><pre>";
 	$rv .= "<b\nid=$id>$subj</b>\n";
 	$rv .= "- $from @ $ts UTC - ";
 	$rv .= "<a\nhref=\"#s$next\">next</a>";
@@ -206,8 +207,8 @@ sub emit_thread_html {
 	$next .= "\ndownload thread: ";
 	$next .= "<a\n$MBOX_TITLE\nhref=\"../t.mbox.gz\">mbox.gz</a>";
 	$next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
-	$cb->write("<hr />" . PublicInbox::Hval::PRE . $next . "\n\n".
-		$foot .  "</pre></body></html>");
+	$cb->write('<hr /><pre>' . $next . "\n\n".
+			$foot .  '</pre></body></html>');
 	$cb->close;
 }
 
@@ -451,8 +452,8 @@ sub headers_to_html_header {
 	}
 	$rv .= "\n";
 
-	("<html><head><title>".  join(' - ', @title) .
-	 "</title>$atom</head><body>" . PublicInbox::Hval::PRE . $rv);
+	("<html><head><title>".  join(' - ', @title) . "</title>$atom".
+	 PublicInbox::Hval::STYLE . "</head><body><pre>" . $rv);
 }
 
 sub thread_inline {
@@ -616,6 +617,7 @@ sub thread_html_head {
 	$$cb->write("<html><head><title>$s</title>".
 		qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
 		qq!href="../t.atom"\ntype="application/atom+xml"/>! .
+		PublicInbox::Hval::STYLE .
 		"</head><body>");
 }
 
@@ -639,8 +641,8 @@ sub ghost_parent {
 sub ghost_table {
 	my ($upfx, $mid, $level) = @_;
 	"<table\nsummary=ghost><tr><td>" .
-		(INDENT x $level) . "</td><td>" .
-		PublicInbox::Hval::PRE . ghost_parent($upfx, $mid) .
+		(INDENT x $level) . '</td><td><pre>' .
+		ghost_parent($upfx, $mid) .
 		'</pre></td></table>';
 }
 
-- 
EW


  reply	other threads:[~2015-12-25 12:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-25 12:06 [PATCH] examples/public-inbox.psgi: make output chunky by default Eric Wong
2015-12-25 12:06 ` Eric Wong [this message]
2015-12-26  0:57   ` [PATCH] searchview: fixup stupid syntax error 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=20151225120630.14664-2-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.
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).