[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 06 Jun 2005 02:16:12 -0000


albertel		Sun Jun  5 22:16:12 2005 EDT

  Modified files:              
    /loncom/interface	lonfeedback.pm 
  Log:
  - bug#2667, can;t do blin \n to <b /> replaces since, well the newlines might be inside ofa tag. need to parse the HTMl to get it correct
  
  
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.164 loncom/interface/lonfeedback.pm:1.165
--- loncom/interface/lonfeedback.pm:1.164	Tue May 24 11:15:59 2005
+++ loncom/interface/lonfeedback.pm	Sun Jun  5 22:16:09 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.164 2005/05/24 15:15:59 albertel Exp $
+# $Id: lonfeedback.pm,v 1.165 2005/06/06 02:16:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1205,7 +1205,7 @@
         my ($timesent,$attachmsg);
         my %currattach = ();
         $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
-        $$messages{$i}=~s/\n/\<br \/\>/g;
+	&newline_to_br(\$messages->{$i});
         $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
         $$subjects{$i}=~s/\n/\<br \/\>/g;
         $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
@@ -1375,7 +1375,7 @@
                   &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
                   $message = $msgversions{$numoldver};
               }
-	      $message=~s/\n/\<br \/\>/g;
+	      &newline_to_br(\$message);
 	      $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
               if ($idx > 0) {
                   my %subversions = ();
@@ -2603,7 +2603,7 @@
     &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;
     my $message=&clear_out_html($env{'form.comment'});
-    $message=~s/\n/\<br \/\>/g;
+    &newline_to_br(\$message);
     $message=&Apache::lonspeller::markeduptext($message);
     $message=&Apache::lontexconvert::msgtexconverted($message);
     my $subject=&clear_out_html($env{'form.subject'});
@@ -2616,6 +2616,28 @@
 	      $message.'</td></tr></table></body></html>');
 }
 
+
+sub newline_to_br {
+    my ($message)=@_;
+    my $newmessage;
+    my $parser=HTML::LCParser->new($message);
+    while (my $token=$parser->get_token()) {
+	if ($token->[0] eq 'T') {
+	    my $text=$token->[1];
+	    $text=~s/\n/\<br \/\>/g;
+	    $newmessage.=$text;
+	} elsif ($token->[0] eq 'D' || $token->[0] eq 'C') {
+	    $newmessage.=$token->[1];
+	} elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') {
+	    $newmessage.=$token->[2];
+	} elsif ($token->[0] eq 'S') {
+	    $newmessage.=$token->[4];
+	}
+	    
+    }
+    $$message=$newmessage;
+}
+
 sub generate_preview_button {
     my $pre=&mt("Show Preview and Check Spelling");
     return(<<ENDPREVIEW);