mhonarc-commits
[Top] [All Lists]

CVS: mhonarc/MHonArc/lib mhtxtplain.pl,2.25,2.26

2002-10-29 18:20:57
Update of /cvsroot/mhonarc/mhonarc/MHonArc/lib
In directory subversions:/tmp/cvs-serv27260

Modified Files:
	mhtxtplain.pl 
Log Message:
* Reworked flowed conversion to fix lack of a line break between
  flowed paragraphs and to preserve multiple line breaks between
  paragraphs.
* Changed inline style for blockquote and added inline style for
  pre for flowed and fancyquote conversion to get proper rendering
  of data.  The style changes are to suppress built-in spacing of
  elements.
* A single one-line paragraph is now rendered non-fixed.  IMO, I
  consider this a violation of RFC 2646, but it appears to be
  the desired behavior by users.


Index: mhtxtplain.pl
===================================================================
RCS file: /cvsroot/mhonarc/mhonarc/MHonArc/lib/mhtxtplain.pl,v
retrieving revision 2.25
retrieving revision 2.26
diff -C2 -r2.25 -r2.26
*** mhtxtplain.pl	26 Oct 2002 22:26:20 -0000	2.25
--- mhtxtplain.pl	30 Oct 2002 01:20:45 -0000	2.26
***************
*** 50,55 ****
  $StartFlowedQuote =
    '<blockquote style="border-left: #0000FF solid 0.1em; '.
!                      'margin-left: 0.0em; padding-left: 1.0em">';
  $EndFlowedQuote   = "</blockquote>";
  
  ##---------------------------------------------------------------------------##
--- 50,57 ----
  $StartFlowedQuote =
    '<blockquote style="border-left: #0000FF solid 0.1em; '.
!                      'margin: 0em; padding-left: 1.0em">';
  $EndFlowedQuote   = "</blockquote>";
+ $StartFixedQuote  = '<pre style="margin: 0em;">';
+ $EndFixedQuote    = '</pre>';
  
  ##---------------------------------------------------------------------------##
***************
*** 273,276 ****
--- 275,280 ----
      my $startq    = "";
      my $endq      = "";
+     my $startfixq = "";
+     my $endfixq   = "";
      my $css_class = "";
      if ($args =~ /\bquoteclass=(\S+)/i) {
***************
*** 285,288 ****
--- 289,294 ----
  				 $StartFlowedQuote;
  	$endq   = $EndFlowedQuote;
+ 	$startfixq = $StartFixedQuote;
+ 	$endfixq   = $EndFixedQuote;
  
      } elsif ($args =~ /\bfancyquote\b/i) {
***************
*** 291,294 ****
--- 297,302 ----
  				 $StartFlowedQuote;
  	$endq   = $EndFlowedQuote;
+ 	$startfixq = $StartFixedQuote;
+ 	$endfixq   = $EndFixedQuote;
  
      } elsif ($args =~ /\bquote\b/i) {
***************
*** 314,317 ****
--- 322,329 ----
      }
  
+     ## Fixup any EOL mess
+     $$data =~ s/\r?\n/\n/g;
+     $$data =~ s/\r/\n/g;
+ 
      ## Convert data according to charset
      if (!$asis{$charset}) {
***************
*** 339,346 ****
  	my $currdepth = 0;
  	my $ret='';
! 	$$data =~ s!^</?x-flowed>\r?\n!!mg;
  	while (length($$data) > 0) {
  	    my($qd) = $$data =~ /^((?:&gt;)*)/;
! 	    if ($$data =~ s/^(.*(?:(?:\n|\r\n?)$qd(?!&gt;).*)*\n?)//) {
  		# divide message into chunks by "quote-depth",
  		# which is the number of leading > signs
--- 351,358 ----
  	my $currdepth = 0;
  	my $ret='';
! 	$$data =~ s!^</?x-flowed>\n!!mg;
  	while (length($$data) > 0) {
  	    my($qd) = $$data =~ /^((?:&gt;)*)/;
! 	    if ($$data =~ s/^(.*(?:\n$qd(?!&gt;).*)*\n?)//) {
  		# divide message into chunks by "quote-depth",
  		# which is the number of leading > signs
***************
*** 350,373 ****
  		$chunk =~ s/^-- $/--/mg; # special case for '-- '
  
! 		my @paras = split(/\r?\n\r?\n/, $chunk);
  		my $para;
  		$chunk = '';
  		foreach $para (@paras) {
! 		    if (($para =~ / \r?\n/) || ($para =~ / \Z/)) {
  			# flowed format
! 			$para =~ s/(^|[^ ])(\r?\n|\Z)/$1<br>$2/mg;
  
  		    } else {
  			# fixed format
  			if ($nonfixed) {
! 			    $para =~ s/(\r?\n)/<br>$1/g;
  			    if ($keepspace) {
  				$para =~ s/^(.*)$/&preserve_space($1)/gem;
  			    }
  			} else {
! 			    $para = '<pre>' . $para . '</pre>';
  			}
  		    }
- 		    $chunk .= $para;
  		}
  
--- 362,394 ----
  		$chunk =~ s/^-- $/--/mg; # special case for '-- '
  
! 		my @paras = split(/(\n\n)/, $chunk);
  		my $para;
  		$chunk = '';
  		foreach $para (@paras) {
! 		    if ($para =~ /\A\n+\Z/) {
! 			$chunk .= "<br>\n" x length($para);
! 			next;
! 		    }
! 		    my $nls = ($para =~ tr/\n/\n/);
! 		    if (($para =~ / \n/) || ($para =~ / \Z/) ||
! 			    ($nls < 1) ||
! 			    (($nls == 1) && ($para =~ /\S/)
! 			     && ($para =~ /\n\Z/))) {
  			# flowed format
! 			$para =~ s/(^|[^ ])(\n)/$1<br>$2/mg;
! 			$chunk .= $para;
  
  		    } else {
  			# fixed format
  			if ($nonfixed) {
! 			    $para =~ s/(\n)/<br>$1/g;
  			    if ($keepspace) {
  				$para =~ s/^(.*)$/&preserve_space($1)/gem;
  			    }
+ 			    $chunk .= $para;
  			} else {
! 			    $chunk .= $startfixq . $para . $endfixq;
  			}
  		    }
  		}
  
***************
*** 395,401 ****
  	}
  
! 	## Post-processing cleanup: makes things look nicer
! 	$ret =~ s/<br><\/blockquote>/<\/blockquote>/g;
! 	$ret =~ s/<\/blockquote><br>/<\/blockquote>/g;
  
  	$$data = $ret;
--- 416,421 ----
  	}
  
! 	## Post-processing cleanup
! 	$ret =~ s/<\/pre>\s*<br>\s*((?:<br>\s*)+)/<\/pre>$1/g;
  
  	$$data = $ret;
***************
*** 405,422 ****
  	my $ret='';
  	while (length($$data) > 0) {
! 	    my($qd) = $$data =~ /^((?:[ ]?(?:${HQuoteChars})[ ]?)*)/;
  	    my($qd_re) = "\Q$qd\E";
  	       $qd_re  =~ s/\\ /[ ]?/g;
! 	    if ($$data =~ s/\A(.*(?:(?:\n|\r\n?)$qd_re
! 			    (?![ ]?(?:${HQuoteChars}[ ]?)).*)*\r?\n?)//x) {
  		my $chunk = $1;
  		$chunk =~ s/^$qd_re//mg;
  		if ($nonfixed) {
! 		    $chunk =~ s/(\r?\n)/<br>$1/g;
  		    if ($keepspace) {
  			$chunk =~ s/^(.*)$/&preserve_space($1)/gem;
  		    }
  		} else {
! 		    $chunk = '<pre>' . $chunk . '</pre>';
  		}
  
--- 425,443 ----
  	my $ret='';
  	while (length($$data) > 0) {
! 	    my($qd) = $$data =~ /^((?:[ ]?(?:${HQuoteChars})[ ]?)*)/o;
  	    my($qd_re) = "\Q$qd\E";
  	       $qd_re  =~ s/\\ /[ ]?/g;
! 	    if ($$data =~ s/\A(.*(?:\n$qd_re
! 			    (?![ ]?(?:${HQuoteChars}[ ]?)).*)*\n?)//x) {
  		my $chunk = $1;
  		$chunk =~ s/^$qd_re//mg;
  		if ($nonfixed) {
! 		    $chunk =~ s/(\n)/<br>$1/g;
  		    if ($keepspace) {
  			$chunk =~ s/^(.*)$/&preserve_space($1)/gem;
  		    }
  		} else {
! 		    $chunk =~ s/\n/<br\n>/g;
! 		    $chunk = $startfixq . $chunk . $endfixq;
  		}
  
***************
*** 444,451 ****
  	    $ret .= $endq x $currdepth;
  	}
- 
- 	## Post-processing cleanup: makes things look nicer
- 	$ret =~ s/<pre>\r?\n/<pre>/g;
- 	$ret =~ s/\r?\n<\/pre>/<\/pre>/g;
  
  	$$data = $ret;
--- 465,468 ----

---------------------------------------------------------------------
To sign-off this list, send email to majordomo(_at_)mhonarc(_dot_)org with the
message text UNSUBSCRIBE MHONARC-DEV