user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] view: consolidate whitespace stripping from messages
@ 2016-03-01  2:48  7% Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2016-03-01  2:48 UTC (permalink / raw)
  To: meta

We now keep intermediate blank lines in messages, since it
could be used to denote logical gaps in the message
(such as giving readers a chance to opt out of "spoiler"
information).

However leading blank lines, trailing blank lines, and
trailing whitespace have no useful value we can discern;
so drop those entirely to prevent clients from eating up
vertical whitespace.
---
 lib/PublicInbox/View.pm | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index de7bdf9..61eb890 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -254,15 +254,10 @@ sub index_walk {
 	my ($fh, $part, $enc, $part_nr, $fhref, $more) = @_;
 	my $s = add_text_body($enc, $part, $part_nr, $fhref);
 
-	# kill any leading or trailing whitespace lines
-	$s =~ s/^\s*$//sgm;
-	$s =~ s/\s+\z//s;
+	return if $s eq '';
+
+	$s .= "\n"; # ensure there's a trailing newline
 
-	if ($s ne '') {
-		# kill per-line trailing whitespace
-		$s =~ s/[ \t]+$//sgm;
-		$s .= "\n" unless $s =~ /\n\z/s;
-	}
 	$fh->write($s);
 }
 
@@ -289,7 +284,9 @@ sub multipart_text_as_html {
 	# scan through all parts, looking for displayable text
 	$mime->walk_parts(sub {
 		my ($part) = @_;
-		$rv .= add_text_body($enc, $part, \$part_nr, $full_pfx, 1);
+		$part = add_text_body($enc, $part, \$part_nr, $full_pfx, 1);
+		$rv .= $part;
+		$rv .= "\n" if $part ne '';
 	});
 	$mime->body_set('');
 	$rv;
@@ -435,8 +432,11 @@ sub add_text_body {
 		$s .= flush_quote(\@quot, \$n, $$part_nr, $full_pfx, 1,
 				  $do_anchor);
 	}
-	$s .= "\n" unless $s =~ /\n\z/s;
 	++$$part_nr;
+
+	$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;
 }
 
-- 
EW


^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-03-01  2:48  7% [PATCH] view: consolidate whitespace stripping from messages Eric Wong

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