]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: favor whitespace wrap in <head>
authorEric Wong <e@80x24.org>
Fri, 25 Dec 2015 11:48:27 +0000 (11:48 +0000)
committerEric Wong <e@80x24.org>
Fri, 25 Dec 2015 12:05:50 +0000 (12:05 +0000)
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
lib/PublicInbox/Hval.pm
lib/PublicInbox/SearchView.pm
lib/PublicInbox/View.pm

index 150bea038241b57addb71cd34866d71cac3f7c7f..7ebc0505602f5e11d6ce5b39fc8d8b4ebf461805 100644 (file)
@@ -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
index e0b85c685c58d0b8824d0e19d39560f0920605ca..5a869358d1b8029d3e2a0a9f4f386b1d26fa5090 100644 (file)
@@ -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');
 
index fec4f39f84d8841c19ce0dc0f10862eed2de2579..5b15e0d7e2fed72ef84fe0785d34f8e2ffd5dfc3 100644 (file)
@@ -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);
index 523d27fe997b09394619b8ae6136a8631625ab96..7603c514cf999c9b01095d697a1698ebbe3dcc58 100644 (file)
@@ -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>';
 }