[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm

foxr lon-capa-cvs@mail.lon-capa.org
Thu, 07 Jul 2005 10:09:52 -0000


This is a MIME encoded message

--foxr1120730992
Content-Type: text/plain

foxr		Thu Jul  7 06:09:52 2005 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Bug 3948 - Re-do how <p> ends... force </p> at several begin tags that
  do new para like things.  This prevents the crashes described in this bug
  both for the case described and for other similar cases.  Note that
  
  
  
--foxr1120730992
Content-Type: text/plain
Content-Disposition: attachment; filename="foxr-20050707060952.txt"

Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.276 loncom/xml/londefdef.pm:1.277
--- loncom/xml/londefdef.pm:1.276	Tue Jul  5 14:59:03 2005
+++ loncom/xml/londefdef.pm	Thu Jul  7 06:09:50 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.276 2005/07/05 18:59:03 albertel Exp $
+# $Id: londefdef.pm,v 1.277 2005/07/07 10:09:50 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -565,11 +565,11 @@
 
 sub end_body {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off unclosed <p>
     if ($target eq 'web') {
-	$currentstring = &Apache::lonxml::xmlend($target,$parser);
+	$currentstring .= &Apache::lonxml::xmlend($target,$parser);
     } elsif ($target eq 'tex') {
-	$currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}';  
+	$currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}';  
     } 
     return $currentstring;
 }
@@ -577,11 +577,11 @@
 #-- <center> tag (end tag required)
 sub start_center {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off any prior para.
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
-	$currentstring = '\begin{center}';  
+	$currentstring .= '\begin{center}';  
     }
     return $currentstring;
 }
@@ -646,7 +646,7 @@
 #-- <h1> tag (end tag required)
 sub start_h1 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -663,7 +663,7 @@
 	if (not defined $TeXsize) {$TeXsize="large";}
 	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
     } elsif ($target eq 'meta') {
-	$currentstring='<subject>';
+	$currentstring.='<subject>';
 	&start_output($target);
     }
     return $currentstring;
@@ -695,7 +695,7 @@
 #-- <h2> tag
 sub start_h2 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -738,7 +738,7 @@
 #-- <h3> tag
 sub start_h3 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -781,7 +781,7 @@
 #-- <h4> tag
 sub start_h4 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -824,7 +824,7 @@
 #-- <h5> tag
 sub start_h5 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off any prior paras.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -867,7 +867,7 @@
 #-- <h6> tag
 sub start_h6 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off any prior paras.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -1114,52 +1114,64 @@
     return $currentstring;
 }
 
+#  <p> is a bit strange since it does not require a closing </p>
+#  However in latex, we must often output closing stuff to end
+#  environments and {}'s etc.  Therefore we do all the work
+#  of figuring out the ending strings in the start tag processing,
+#  and provide a mechanism to output the stop text external
+#  to tag processing.
+#
+{
+
+    my $closing_string = '';		# String required to close <p>
+
 #-- <p> tag (end tag optional)
 #optional attribute - align="center|left|right"
 sub start_p {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# close off prior para if in progress.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
+	$closing_string = '</p>'; # Not sure this is correct.
     } elsif ($target eq 'tex') {
 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 	if ($align eq 'center') {
-	    $currentstring='\begin{center}\par';
+	    $currentstring .='\begin{center}\par';
+	    $closing_string = '\end{center}';
 	} elsif ($align eq 'right') {
-	    $currentstring='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{';
+	    $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{';
+	    $closing_string= '}}';
 	} elsif ($align eq 'left') {
-	    $currentstring='\noindent\makebox['.$env{'form.textwidth'}.']{\rlap{';
+	    $currentstring.='\noindent\makebox['.$env{'form.textwidth'}.']{\rlap{';
+	    $closing_string = '}\hfill}';
 	} else {
-            $currentstring='\par ';
+            $currentstring.='\par ';
+	    $closing_string = '\strut\\\\\strut';
         }
 	my $signal=1;#<p> does not work inside <b>...</b> 
-	foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}
-	if (!$signal) {$currentstring = '';}
+	foreach my $tag (@$tagstack) {
+	    if (lc($tag) eq 'b') {
+		$signal=0;
+	    }
+	}
+	if (!$signal) {
+	    $currentstring = &end_p; # Just close the prior? Not sure this is correct
+	    $closing_string = '';    # Probably correct?
 	}
-    }
-    return $currentstring;
-}
 
-sub end_p {
-    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
-    if ($target eq 'web') {
-	$currentstring .= $token->[2];
-    } elsif ($target eq 'tex') {
-	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
-	if (not defined $align) {
-	    $currentstring.='\strut\\\\\strut ';
-	} elsif ($align eq 'center') {		
-	    $currentstring .= '\end{center}';
-	} elsif ($align eq 'right') {
-	    $currentstring .= '}}';
-	} elsif ($align eq 'left') {
-	    $currentstring .= '}\hfill}';
-	} 
     }
     return $currentstring;
 }
+#
+#  End paragraph processing just requires that we output the
+#  closing string that was saved and blank it.
+sub end_p {
+    my $current_string = $closing_string;
+    $closing_string = '';	# Not in a para anymore.
+    return $current_string;
 
+}
+}
 #-- <br> tag (end tag forbidden)
 sub start_br {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
@@ -1405,7 +1417,7 @@
 #-- <hr> tag (end tag forbidden)
 sub start_hr {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# End enclosing para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -1445,7 +1457,7 @@
 #-- <div> tag (end tag required)
 sub start_div {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close enclosing para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } 
@@ -1527,9 +1539,9 @@
 
 sub end_li {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# In case there's a <p> in the <li>
     if ($target eq 'web') {
-	$currentstring = $token->[2];     
+	$currentstring .= $token->[2];     
     } 
     return $currentstring;
 }
@@ -1563,9 +1575,9 @@
 #-- <ul> tag (end tag required)
 sub start_ul {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off enclosing list.
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
 	my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
 	$Apache::londefdef::list_index=0;
@@ -1630,11 +1642,11 @@
 #-- <dir> tag (end tag required)
 sub start_dir {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# In case there's a <p> prior to the list.
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
-	$currentstring = " \\begin{itemize} ";  
+	$currentstring .= " \\begin{itemize} ";  
     } 
     return $currentstring;
 }
@@ -1653,9 +1665,9 @@
 #-- <ol> tag (end tag required)
 sub start_ol {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# In case there's a <p> prior to the list.
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
 	$Apache::londefdef::list_index=0;
 	my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
@@ -1707,11 +1719,11 @@
 #-- <dl> tag (end tag required)
 sub start_dl {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# In case there's a <p> unclosed prior to the list.
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
-	$currentstring = '\begin{description}';
+	$currentstring .= '\begin{description}';
 	$Apache::londefdef::DL++;
 	push(@Apache::londefdef::description,[]);
 	$Apache::londefdef::DD[$Apache::londefdef::DL]=0;
@@ -1814,12 +1826,18 @@
 }
 
 #-- <table> tag (end tag required)
+#       <table> also ends any prior <p> that is not closed.
+#               but, unless I allow <p>'s to nest, that's the
+#               only way I could think of to allow <p> in 
+#               <tr> <th> bodies
+#
 #list of supported attributes: border,width,TeXwidth
 sub start_table {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my ($textwidth,$currentstring)=('','');
+    my $textwidth = '';
+    my $currentstring = &end_p;
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
 	my $aa = {};
 	push @Apache::londefdef::table, $aa; 
@@ -1883,7 +1901,7 @@
         $Apache::londefdef::table[-1]{'minlen'}=[];
         $Apache::londefdef::table[-1]{'content'}=[];
         $Apache::londefdef::table[-1]{'align'}=[];
-        $currentstring='\keephidden{NEW TABLE ENTRY}';
+        $currentstring.='\keephidden{NEW TABLE ENTRY}';
    }
     return $currentstring;
 }
@@ -2137,9 +2155,9 @@
         
 sub end_tr {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close any pending <p> in the row.
     if ($target eq 'web') {
-	$currentstring = $token->[2];     
+	$currentstring .= $token->[2];     
     } elsif ($target eq 'tex') {
 	if ($Apache::londefdef::TD_redirection) {
 	    &end_td_tex($parstack,$parser,$safeeval);    
@@ -2414,9 +2432,9 @@
 
 sub end_th {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close any open <p> in the row.
     if ($target eq 'web') {
-	$currentstring = $token->[2];     
+	$currentstring .= $token->[2];     
     } elsif ($target eq 'tex') {
         $Apache::londefdef::TD_redirection =0;
 	&end_th_tex($parstack,$parser,$safeeval);
@@ -2795,7 +2813,7 @@
 #-- <frameset>
 sub start_frameset {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = '';	# Close any pending para.
     if ($target eq 'web') { 
 	if (!$Apache::lonxml::registered &&
 	    $env{'request.state'} eq 'published') {
@@ -2864,7 +2882,7 @@
 #-- <pre> (end tag required)
 sub start_pre {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# close off pending <p>
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -2927,7 +2945,7 @@
 #-- <blankspace heigth="">
 sub start_blankspace {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# closes off any unclosed <p>
     if ($target eq 'tex') {
 	my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
 	$currentstring .= '\vskip '.$howmuch.' ';
@@ -3080,9 +3098,9 @@
 #-- <blockquote> tag (end tag required)
 sub start_blockquote {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close any unclosed <p>
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } 
     return $currentstring;
 }
@@ -3403,9 +3421,9 @@
 #-- <multicol> tag (end tag required)
 sub start_multicol {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close any pending <p>
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } 
     return $currentstring;
 }
@@ -3601,9 +3619,9 @@
 #-- <spacer> tag (end tag forbidden)
 sub start_spacer {
     my ($target,$token) = @_;
-    my $currentstring = '';
+    my $currentstring = &end_p;	# Close off any open <p> tag.
     if ($target eq 'web') {
-	$currentstring = $token->[4];     
+	$currentstring .= $token->[4];     
     } 
     return $currentstring;
 }

--foxr1120730992--