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

foxr lon-capa-cvs@mail.lon-capa.org
Mon, 11 Jul 2005 09:50:01 -0000


This is a MIME encoded message

--foxr1121075401
Content-Type: text/plain

foxr		Mon Jul 11 05:50:01 2005 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Fix various issues with <p> that don't have end tags in tex mode.
  
  
--foxr1121075401
Content-Type: text/plain
Content-Disposition: attachment; filename="foxr-20050711055001.txt"

Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.278 loncom/xml/londefdef.pm:1.279
--- loncom/xml/londefdef.pm:1.278	Sun Jul 10 17:43:35 2005
+++ loncom/xml/londefdef.pm	Mon Jul 11 05:49:59 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.278 2005/07/10 21:43:35 www Exp $
+# $Id: londefdef.pm,v 1.279 2005/07/11 09:49:59 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -563,7 +563,7 @@
 
 sub end_body {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close off unclosed <p>
+    my $currentstring = &end_p();	# Close off unclosed <p>
     if ($target eq 'web') {
 	$currentstring .= &Apache::lonxml::xmlend($target,$parser);
     } elsif ($target eq 'tex') {
@@ -575,7 +575,7 @@
 #-- <center> tag (end tag required)
 sub start_center {
     my ($target,$token) = @_;
-    my $currentstring = &end_p;	# Close off any prior para.
+    my $currentstring = &end_p();	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
@@ -596,13 +596,15 @@
 }
 
 #-- <b> tag (end tag required)
+#      NOTE: In TeX mode disables internal <p>
 sub start_b {
     my ($target,$token) = @_;
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring = $token->[4];     
     } elsif ($target eq 'tex') {
-	$currentstring = '\textbf{';  
+	&disable_para();
+	$currentstring .= '\textbf{';  
     } 
     return $currentstring;
 }
@@ -613,18 +615,21 @@
     if ($target eq 'web') {
 	$currentstring = $token->[2];     
     } elsif ($target eq 'tex') {
-	$currentstring = '}';  
+	&enable_para();
+	$currentstring = '}';
     } 
     return $currentstring;
 }
 
 #-- <strong> tag (end tag required)
+#    NOTE: in TeX mode disables internal <p>
 sub start_strong {
     my ($target,$token) = @_;
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring = $token->[4];     
     } elsif ($target eq 'tex') {
+	&disable_para();
 	$currentstring = '\textbf{';  
     } 
     return $currentstring;
@@ -636,6 +641,7 @@
     if ($target eq 'web') {	
 	$currentstring = $token->[2];     
     } elsif ($target eq 'tex') {
+	&enable_para();
 	$currentstring = '}';  
     }
     return $currentstring;
@@ -644,7 +650,7 @@
 #-- <h1> tag (end tag required)
 sub start_h1 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close off any prior para.
+    my $currentstring = &end_p();	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -693,7 +699,7 @@
 #-- <h2> tag
 sub start_h2 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close off any prior para.
+    my $currentstring = &end_p();	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -736,7 +742,7 @@
 #-- <h3> tag
 sub start_h3 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close off any prior para.
+    my $currentstring = &end_p();	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -779,7 +785,7 @@
 #-- <h4> tag
 sub start_h4 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close off any prior para.
+    my $currentstring = &end_p();	# Close off any prior para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -822,7 +828,7 @@
 #-- <h5> tag
 sub start_h5 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close off any prior paras.
+    my $currentstring = &end_p();	# Close off any prior paras.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -865,7 +871,7 @@
 #-- <h6> tag
 sub start_h6 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close off any prior paras.
+    my $currentstring = &end_p();	# Close off any prior paras.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -1123,15 +1129,34 @@
 
     my $closing_string = '';		# String required to close <p>
 
+#   Some tags are <p> fragile meaning that <p> inside of them
+#   does not work within TeX mode.  This is managed via the 
+#   counter below:
+#
+
+    my $para_disabled = 0;
+
+sub disable_para {
+    $para_disabled++;
+}
+sub enable_para {
+    $para_disabled--;
+}
+
+
 #-- <p> tag (end tag optional)
 #optional attribute - align="center|left|right"
 sub start_p {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# close off prior para if in progress.
+    my $currentstring = '';
     if ($target eq 'web') {
+	$currentstring .= &end_p();	# close off prior para if in progress.
 	$currentstring .= $token->[4];
-	$closing_string = '</p>'; # Not sure this is correct.
-    } elsif ($target eq 'tex') {
+	if (! ($currentstring =~ /\//)) {
+	    $closing_string = '</p>'; # Deal correctly with <p /> e.g.
+	}
+    } elsif ($target eq 'tex' && !$para_disabled) {
+	$currentstring .= &end_p();	# close off prior para if in progress.
 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 	if ($align eq 'center') {
 	    $currentstring .='\begin{center}\par';
@@ -1144,18 +1169,8 @@
 	    $closing_string = '}\hfill}';
 	} else {
             $currentstring.='\par ';
-	    $closing_string = '\strut\\\\\strut';
+	    $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 = &end_p; # Just close the prior? Not sure this is correct
-	    $closing_string = '';    # Probably correct?
-	}
 
     }
     return $currentstring;
@@ -1164,9 +1179,16 @@
 #  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;
+    #  Note only 'tex' mode uses disable_para and enable_para
+    #  so we don't need to know the target in the check below:
+
+    if (!$para_disabled) {
+	my $current_string = $closing_string;
+	$closing_string = '';	# Not in a para anymore.
+	return $current_string;
+    } else {
+	return '';
+    }
 
 }
 }
@@ -1415,7 +1437,7 @@
 #-- <hr> tag (end tag forbidden)
 sub start_hr {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# End enclosing para.
+    my $currentstring = &end_p();	# End enclosing para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -1455,7 +1477,7 @@
 #-- <div> tag (end tag required)
 sub start_div {
     my ($target,$token) = @_;
-    my $currentstring = &end_p;	# Close enclosing para.
+    my $currentstring = &end_p();	# Close enclosing para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } 
@@ -1537,7 +1559,7 @@
 
 sub end_li {
     my ($target,$token) = @_;
-    my $currentstring = &end_p;	# In case there's a <p> in the <li>
+    my $currentstring = &end_p();	# In case there's a <p> in the <li>
     if ($target eq 'web') {
 	$currentstring .= $token->[2];     
     } 
@@ -1573,7 +1595,7 @@
 #-- <ul> tag (end tag required)
 sub start_ul {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close off enclosing list.
+    my $currentstring = &end_p();	# Close off enclosing list.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
@@ -1640,7 +1662,7 @@
 #-- <dir> tag (end tag required)
 sub start_dir {
     my ($target,$token) = @_;
-    my $currentstring = &end_p;	# In case there's a <p> prior to the list.
+    my $currentstring = &end_p();	# In case there's a <p> prior to the list.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
@@ -1663,7 +1685,7 @@
 #-- <ol> tag (end tag required)
 sub start_ol {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# In case there's a <p> prior to the list.
+    my $currentstring = &end_p();	# In case there's a <p> prior to the list.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
@@ -1717,7 +1739,7 @@
 #-- <dl> tag (end tag required)
 sub start_dl {
     my ($target,$token) = @_;
-    my $currentstring = &end_p;	# In case there's a <p> unclosed prior to the list.
+    my $currentstring = &end_p();	# In case there's a <p> unclosed prior to the list.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
@@ -1833,7 +1855,7 @@
 sub start_table {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $textwidth = '';
-    my $currentstring = &end_p;
+    my $currentstring = &end_p();
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } elsif ($target eq 'tex') {
@@ -2153,7 +2175,7 @@
         
 sub end_tr {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close any pending <p> in the row.
+    my $currentstring = &end_p();	# Close any pending <p> in the row.
     if ($target eq 'web') {
 	$currentstring .= $token->[2];     
     } elsif ($target eq 'tex') {
@@ -2430,7 +2452,7 @@
 
 sub end_th {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# Close any open <p> in the row.
+    my $currentstring = &end_p();	# Close any open <p> in the row.
     if ($target eq 'web') {
 	$currentstring .= $token->[2];     
     } elsif ($target eq 'tex') {
@@ -2880,7 +2902,7 @@
 #-- <pre> (end tag required)
 sub start_pre {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# close off pending <p>
+    my $currentstring = &end_p();	# close off pending <p>
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
@@ -2943,7 +2965,7 @@
 #-- <blankspace heigth="">
 sub start_blankspace {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
-    my $currentstring = &end_p;	# closes off any unclosed <p>
+    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.' ';
@@ -3096,7 +3118,7 @@
 #-- <blockquote> tag (end tag required)
 sub start_blockquote {
     my ($target,$token) = @_;
-    my $currentstring = &end_p;	# Close any unclosed <p>
+    my $currentstring = &end_p();	# Close any unclosed <p>
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } 
@@ -3419,7 +3441,7 @@
 #-- <multicol> tag (end tag required)
 sub start_multicol {
     my ($target,$token) = @_;
-    my $currentstring = &end_p;	# Close any pending <p>
+    my $currentstring = &end_p();	# Close any pending <p>
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } 
@@ -3617,7 +3639,7 @@
 #-- <spacer> tag (end tag forbidden)
 sub start_spacer {
     my ($target,$token) = @_;
-    my $currentstring = &end_p;	# Close off any open <p> tag.
+    my $currentstring = &end_p();	# Close off any open <p> tag.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];     
     } 

--foxr1121075401--