--- loncom/xml/londefdef.pm 2003/07/14 14:29:26 1.153 +++ loncom/xml/londefdef.pm 2003/09/02 21:31:11 1.158.4.6 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.153 2003/07/14 14:29:26 sakharuk Exp $ +# $Id: londefdef.pm,v 1.158.4.6 2003/09/02 21:31:11 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -25,8 +25,7 @@ # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ -# -# Copyright for TtHfunc and TtMfunc by Ian Hutchinson. +## Copyright for TtHfunc and TtMfunc by Ian Hutchinson. # TtHfunc and TtMfunc (the "Code") may be compiled and linked into # binary executable programs or libraries distributed by the # Michigan State University (the "Licensee"), but any binaries so @@ -320,7 +319,7 @@ sub start_title { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\keephidden{' + $currentstring .= '\keephidden{Title of the document: ' } if ($target eq 'meta') { $currentstring=''; @@ -364,11 +363,25 @@ sub start_meta { $name=~s/\s/\_/gs; $name=~s/\W//gs; if ($name) { - $currentstring='<'.$name.'>'. + $currentstring='<'.$name; + my $display=&Apache::lonxml::get_param + ('display',$parstack,$safeeval,undef,1); + if ($display) { + $display=~s/\"/\'/g; + $currentstring.=' display="'.$display.'"'; + } + $currentstring.='>'. &Apache::lonxml::get_param ('content',$parstack,$safeeval,undef,1). '</'.$name.'>'; } + my $display=&Apache::lonxml::get_param + ('display',$parstack,$safeeval,undef,1); + if ($display) { + $display=&HTML::Entities::encode($display); + $currentstring.='<'.$name.'.display>'.$display. + '</'.$name.'.display>'; + } } } elsif ($target eq 'tex') { my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); @@ -381,7 +394,7 @@ sub start_meta { } sub end_meta { - my ($target,$token,$tagstack,$parstack,$parser) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { my $args=''; @@ -390,8 +403,11 @@ sub end_meta { $currentstring = $token->[4]; } } elsif ($target eq 'tex') { - $currentstring=&Apache::lonxml::endredirection(); - $currentstring=''; + 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(); + } } return $currentstring; } @@ -446,10 +462,37 @@ sub start_body { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { + if ($Apache::lonhomework::parsing_a_problem) { + &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems."); + return ''; + } if (!$Apache::lonxml::registered) { $currentstring.='<head>'. &Apache::lonmenu::registerurl(undef,$target).'</head>'; } +# Accessibility + if ($ENV{'browser.imagesuppress'} eq 'on') { + delete($token->[2]->{'background'}); + } + if ($ENV{'browser.fontenhance'} eq 'on') { + my $style=''; + foreach my $key (keys(%{$token->[2]})) { + if ($key =~ /^style$/i) { + $style.=$token->[2]->{$key}.';'; + delete($token->[2]->{$key}); + } + } + $token->[2]->{'style'}=$style.'; font-size: x-large;'; + } + if ($ENV{'browser.blackwhite'} eq 'on') { + delete($token->[2]->{'font'}); + delete($token->[2]->{'link'}); + delete($token->[2]->{'alink'}); + delete($token->[2]->{'vlink'}); + delete($token->[2]->{'bgcolor'}); + delete($token->[2]->{'background'}); + } +# Overload loads my $onLoad=''; foreach my $key (keys(%{$token->[2]})) { if ($key =~ /^onload$/i) { @@ -1042,12 +1085,14 @@ sub end_q { #-- <p> tag sub start_p { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\par '; + my $signal=1; + foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}} + if ($signal) {$currentstring .= '\par ';} } return $currentstring; } @@ -1165,7 +1210,12 @@ sub start_font { my $currentstring = ''; if ($target eq 'web') { my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval); - if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode++;} + if ($face=~/symbol/i) { + $Apache::lonxml::prevent_entity_encode++; + } else { + if (($ENV{'browser.fontenhance'} eq 'on') || + ($ENV{'browser.blackwhite'} eq 'on')) { return ''; } + } $currentstring = $token->[4]; } elsif ($target eq 'tex') { my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval); @@ -1364,7 +1414,7 @@ sub start_a { } sub end_a { - my ($target,$token,$tagstack,$parstack,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; @@ -1374,7 +1424,7 @@ sub end_a { #-- <li> tag sub start_li { - my ($target,$token,$tagstack,$parstack,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; @@ -1738,7 +1788,7 @@ sub end_table { $needed=$#length_row_final-$needed+1; for (my $jn=0;$jn<=$#length_row_final;$jn++) { if ($length_row_final[$jn]==0) { - if ($length_raw_row[$jn]<$available_length/3) { + if ($length_raw_row[$jn]<$available_length) { $length_row_final[$jn]=$length_raw_row[$jn]; $available_length=$available_length-$length_raw_row[$jn]; $needed--; @@ -1774,7 +1824,7 @@ sub end_table { return $currentstring; } -#-- <tr> tag +#-- <tr> tag (end tag optional) sub start_tr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1808,7 +1858,7 @@ sub end_tr { return $currentstring; } -#-- <td> tag +#-- <td> tag (end tag optional) sub start_td { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1847,12 +1897,27 @@ sub end_td { $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; $Apache::londefdef::table[-1]{'length'} .= '0,'; } else { - $data=~s/^\s+(\S.*)/$1/; + $data=~s/^\s+(\S.*)/$1/; $data=~s/(.*\S)\s+$/$1/; - my $current_length=2*length($data); + $data=~s/(\s)+/$1/; + my $current_length=0; + if ($data=~/\\vskip/) { + my $newdata=$data; + $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g; + my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata); + foreach my $elementdata (@newdata) { + $elementdata=~s/^\s+(\S.*)/$1/; + $elementdata=~s/(.*\S)\s+$/$1/; + $elementdata=~s/(\s)+/$1/; + my $lengthnewdata=1.8*length($elementdata); + if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;} + } + } else { + $current_length=1.8*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]/; @@ -1862,7 +1927,7 @@ sub end_td { return $currentstring; } -#-- <th> tag +#-- <th> tag (end tag optional) sub start_th { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1928,10 +1993,9 @@ sub start_img { my $width_param = ''; my $height_param = ''; my $scaling = .3; - if ($target eq 'web') { if ($ENV{'browser.imagesuppress'} ne 'on') { - $currentstring = $token->[4]; + $currentstring.= $token->[4]; } else { my $alttag= &Apache::lonxml::get_param ('alt',$parstack,$safeeval,undef,1); @@ -1939,12 +2003,11 @@ sub start_img { $alttag=&Apache::lonmeta::alttag ($Apache::lonxml::pwd[-1],$src); } - $currentstring='[IMAGE: '.$alttag.']'; + $currentstring.='[IMAGE: '.$alttag.']'; } } elsif ($target eq 'tex') { $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); &image_replication($src); - #if original gif/jpg/png file exist do following: if (-e $src) { #defines the default size of image @@ -1969,6 +2032,7 @@ sub start_img { } elsif ($width ne '') { $width_param = $width*$scaling; } + if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}} my $file; my $path; if ($src =~ m!(.*)/([^/]*)$!) { @@ -2994,7 +3058,7 @@ sub end_tbody { return $currentstring; } -#-- <tfoot> tag +#-- <tfoot> tag (end tag optional) sub start_tfoot { my ($target,$token) = @_; my $currentstring = ''; @@ -3013,7 +3077,7 @@ sub end_tfoot { return $currentstring; } -#-- <thead> tag +#-- <thead> tag (end tag optional) sub start_thead { my ($target,$token) = @_; my $currentstring = '';