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

sakharuk lon-capa-cvs@mail.lon-capa.org
Thu, 07 Aug 2003 20:12:40 -0000


sakharuk		Thu Aug  7 16:12:40 2003 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Now it's possible to use unbalanced <td> tag (av=ccording standard HTML </td> tag is optional) except at the end of raw. Continue to work with.
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.158 loncom/xml/londefdef.pm:1.159
--- loncom/xml/londefdef.pm:1.158	Fri Aug  1 09:35:20 2003
+++ loncom/xml/londefdef.pm	Thu Aug  7 16:12:40 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.158 2003/08/01 13:35:20 sakharuk Exp $
+# $Id: londefdef.pm,v 1.159 2003/08/07 20:12:40 sakharuk Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -1858,49 +1858,90 @@
     if ($target eq 'web') {
 	$currentstring = $token->[4];     
     } elsif ($target eq 'tex') {
-	my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
-	if ($what_to_push eq '') {
-	    $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
-	}
-	push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
-	$Apache::londefdef::table[-1]{'counter_columns'}++;
-	&Apache::lonxml::startredirection();
+	&tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
+#	my @ar=@$parstack; 
+#	for (my $i=$#ar-1;$i>=0;$i--) {
+#	    if (lc($$tagstack[$i]) eq 'tr') {
+#		&start_td_tex($parstack,$parser,$safeeval);
+#		last;
+#	    } elsif (lc($$tagstack[$i]) eq 'td') {
+#                splice @ar, $i+1;
+#		&end_td_tex(\@ar,$parser,$safeeval);
+#		&start_td_tex($parstack,$parser,$safeeval);
+#		last;
+#	    }
+#	}
     } 
     return $currentstring;
 }   
-     
+    
+sub tag_check {
+    my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
+	my @ar=@$parstack; 
+	for (my $i=$#ar-1;$i>=0;$i--) {
+	    if (lc($$tagstack[$i]) eq $good_tag) {
+		&start_td_tex($parstack,$parser,$safeeval);
+		last;
+	    } elsif (lc($$tagstack[$i]) eq $bad_tag) {
+                splice @ar, $i+1;
+		&end_td_tex(\@ar,$parser,$safeeval);
+		&start_td_tex($parstack,$parser,$safeeval);
+		last;
+	    }
+	}
+    return '';
+}
+ 
+sub start_td_tex {
+    my ($parstack,$parser,$safeeval) = @_;
+    my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
+    if ($what_to_push eq '') {
+	$what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
+    }
+    push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
+    $Apache::londefdef::table[-1]{'counter_columns'}++;
+    &Apache::lonxml::startredirection();
+    return '';
+}
+
+sub end_td_tex {
+    my ($parstack,$parser,$safeeval) = @_;
+    my $current_row = $Apache::londefdef::table[-1]{'row_number'};
+    my $data=&Apache::lonxml::endredirection();
+    my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
+    if (defined $TeXwidth) {		
+	my $current_length=&recalc($TeXwidth);
+	$current_length=~/(\d+)/;
+	$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
+	$Apache::londefdef::table[-1]{'length'} .= '0,';
+    } else {
+	if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
+	    my $current_length=&recalc($1);
+	    $current_length=~/(\d+\.?\d*)/;
+	    $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
+	    $Apache::londefdef::table[-1]{'length'} .= '0,';
+	} else {  
+	    $data=~s/^\s+(\S.*)/$1/;
+	    $data=~s/(.*\S)\s+$/$1/;
+	    my $current_length=2*length($data);
+	    $Apache::londefdef::table[-1]{'length'} .= $current_length.',';
+	    $Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
+	}        
+    }
+	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {         
+	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
+	}
+    @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
+    return'';
+}
+
 sub end_td {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring = $token->[2];     
     } elsif ($target eq 'tex') {
-	my $current_row = $Apache::londefdef::table[-1]{'row_number'};
-	my $data=&Apache::lonxml::endredirection();
-	my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
-	if (defined $TeXwidth) {		
-	    my $current_length=&recalc($TeXwidth);
-	    $current_length=~/(\d+)/;
-	    $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
-	    $Apache::londefdef::table[-1]{'length'} .= '0,';
-	} else {
-	    if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
-		my $current_length=&recalc($1);
-		$current_length=~/(\d+\.?\d*)/;
-		$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
-		$Apache::londefdef::table[-1]{'length'} .= '0,';
-	    } else {  
-		$data=~s/^\s+(\S.*)/$1/;
-		$data=~s/(.*\S)\s+$/$1/;
-		my $current_length=2*length($data);
-		$Apache::londefdef::table[-1]{'length'} .= $current_length.',';
-		$Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
-	    }        
-	}
-	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {         
-	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
-	}
-	@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
+	&end_td_tex($parstack,$parser,$safeeval);
     }
     return $currentstring;
 }