user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] view: consolidate per-message newline handling
Date: Sat, 18 Jun 2016 08:50:22 +0000	[thread overview]
Message-ID: <20160618085022.18224-1-e@80x24.org> (raw)

We don't want to blindly append a trailing newline
if the message ends in quoted text leading to a <span>,
as a newline is already added to a <span>...
---
 lib/PublicInbox/View.pm | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index e6d30a8..e8ec0ed 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -207,8 +207,6 @@ sub index_walk {
 
 	return if $s eq '';
 
-	$s .= "\n"; # ensure there's a trailing newline
-
 	$fh->write($s);
 }
 
@@ -219,9 +217,7 @@ sub multipart_text_as_html {
 	# scan through all parts, looking for displayable text
 	msg_iter($mime, sub {
 		my ($p) = @_;
-		$p = add_text_body($upfx, $p);
-		$rv .= $p;
-		$rv .= "\n" if $p ne '';
+		$rv .= add_text_body($upfx, $p);
 	});
 	$rv;
 }
@@ -234,7 +230,7 @@ sub flush_quote {
 	my $rv = $l->linkify_1(join('', @$quot));
 	@$quot = ();
 
-	# we use a <div> here to allow users to specify their own
+	# we use a <span> here to allow users to specify their own
 	# color for quoted text
 	$rv = $l->linkify_2(ascii_html($rv));
 	$$s .= qq(<span\nclass="q">) . $rv . '</span>'
@@ -263,7 +259,7 @@ sub attach_link ($$$$) {
 	my @ret = qq($nl<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
 	my $ts = "Type: $ct, Size: $size bytes";
 	push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]");
-	join('', @ret, '</a>');
+	join('', @ret, "</a>\n");
 }
 
 sub add_text_body {
@@ -285,7 +281,7 @@ sub add_text_body {
 	$s = '';
 	if (defined($fn) || $depth > 0) {
 		$s .= attach_link($upfx, $ct, $p, $fn);
-		$s .= "\n\n";
+		$s .= "\n";
 	}
 	my @quot;
 	my $l = PublicInbox::Linkify->new;
@@ -303,11 +299,15 @@ sub add_text_body {
 		}
 	}
 
-	flush_quote(\$s, $l, \@quot) if @quot;
+	my $end = "\n";
+	if (@quot) {
+		$end = '';
+		flush_quote(\$s, $l, \@quot);
+	}
 	$s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
 	$s =~ s/\A\n+//s; # kill leading blank lines
-	$s =~ s/\s+\z//s; # kill all trailing spaces (final "\n" added if ne '')
-	$s;
+	$s =~ s/\s+\z//s; # kill all trailing spaces
+	$s .= $end;
 }
 
 sub _msg_html_prepare {

                 reply	other threads:[~2016-06-18  8:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20160618085022.18224-1-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).