From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A481D1FF40 for ; Sat, 18 Jun 2016 08:50:22 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] view: consolidate per-message newline handling Date: Sat, 18 Jun 2016 08:50:22 +0000 Message-Id: <20160618085022.18224-1-e@80x24.org> List-Id: We don't want to blindly append a trailing newline if the message ends in quoted text leading to a , as a newline is already added to a ... --- 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
here to allow users to specify their own + # we use a here to allow users to specify their own # color for quoted text $rv = $l->linkify_2(ascii_html($rv)); $$s .= qq() . $rv . '' @@ -263,7 +259,7 @@ sub attach_link ($$$$) { my @ret = qq($nl[-- Attachment #$idx: ); my $ts = "Type: $ct, Size: $size bytes"; push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]"); - join('', @ret, ''); + join('', @ret, "\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 {