[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Format=Flowed



Ken Hirsch:
> Perhaps any paragraph (of more than one line) should be treated as 
> fixed if all its lines end without blanks.

Earl Hood:
> The filter code needs to be modified so that within each chunk, the
> chunk is split into separate paragraph units before determining if the
> data is flowed or not.

It seems as we are agreed on this, and I wrote some code accordingly. A 
modified mhtxtplain.pl file and the CVS diff are attached to this message.

Hope you agree it's an improvement.

/ Gunnar

mhtxtplain.pl
CVS diff Format=Flowed modifications (compared to v2.24)
===================================================================
323c323,324
< 		    $chunk =~ s/(^|[^ ])(\r?\n|\Z)/$1<br>$2/mg;
---
> 		    #chunk =~ s/(^|[^ ])(\r?\n|\Z)/$1<br>$2/mg;
> 		    $chunk = &flowed($chunk);
465a467,507
> }
> 
> ##---------------------------------------------------------------------------##
> 
> sub flowed {
>     my $chunk = shift;
>     $chunk =~ s/\r?\n/\n/g;
>     $chunk =~ s/\s+$//;
> 
>     # Special treatment of two or three blank lines (more
>     # than three blank lines are reduced to three)
>     $chunk =~ s/\n{4,}/\n\n<br>\n<br>\n\n/g;
>     $chunk =~ s/\n{3}/\n\n<br>\n\n/g;
> 
>     # Split into paragraphs
>     my @paras = split (/\n\n/, $chunk);
>     for my $para (@paras) {
> 
> 	# Decide if the paragraph is fixed or flowed
> 	my $fixed = 1;
> 	my @lines = split (/\n/, $para);
> 	for (@lines) {
> 	    if (/ $/) {
> 		$fixed = 0;
> 		last;
> 	    }
> 	}
> 
> 	unless ($para =~ /<br>/) {
> 	    if ($fixed) {
> 		$para = "\n<pre>$para\n</pre>";
> 	    } else {
> 		for (@lines) {
> 		    s/([^ ])$/$1<br>/;
> 		}
> 		$para = join ("\n", @lines);
> 	    }
> 	}
>     }
>     $chunk = join ("\n", @paras) . "\n<br>";
>     $chunk;

Attachment: mhtxtplain.zip
Description: Zip compressed data


[Index of Archives]     [Bugtraq]     [Yosemite News]     [Mhonarc Home]