--- loncom/xml/londefdef.pm 2003/08/27 15:00:43 1.158.4.3 +++ loncom/xml/londefdef.pm 2003/08/07 20:12:40 1.159 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.158.4.3 2003/08/27 15:00:43 albertel Exp $ +# $Id: londefdef.pm,v 1.159 2003/08/07 20:12:40 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -394,7 +394,7 @@ sub start_meta { } sub end_meta { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser) = @_; my $currentstring = ''; if ($target eq 'web') { my $args=''; @@ -403,11 +403,8 @@ sub end_meta { $currentstring = $token->[4]; } } elsif ($target eq 'tex') { - my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); - my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); - if ((not defined $content) && (not defined $name)) { - &Apache::lonxml::endredirection(); - } + $currentstring=&Apache::lonxml::endredirection(); + $currentstring=''; } return $currentstring; } @@ -1410,7 +1407,7 @@ sub start_a { } sub end_a { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; @@ -1420,7 +1417,7 @@ sub end_a { #--
  • tag sub start_li { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; @@ -1861,49 +1858,90 @@ sub start_td { 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; }