--- loncom/xml/lonxml.pm 2002/07/24 20:25:23 1.184 +++ loncom/xml/lonxml.pm 2002/09/10 20:53:36 1.194 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.184 2002/07/24 20:25:23 www Exp $ +# $Id: lonxml.pm,v 1.194 2002/09/10 20:53:36 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -154,6 +154,7 @@ sub xmlbegin { } sub xmlend { + my ($discussiononly,$symb)=@_; my $discussion=''; if ($ENV{'request.course.id'}) { my $crs='/'.$ENV{'request.course.id'}; @@ -162,27 +163,35 @@ sub xmlend { } $crs=~s/\_/\//g; my $seeid=&Apache::lonnet::allowed('rin',$crs); - my $symb=&Apache::lonnet::symbread(); + unless ($symb) { + $symb=&Apache::lonnet::symbread(); + } if ($symb) { my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); if ($contrib{'version'}) { - $discussion.= - '

Course Discussion of Resource

'; + unless ($discussiononly) { + $discussion.= + '

'; + } my $idx; for ($idx=1;$idx<=$contrib{'version'};$idx++) { my $hidden=($contrib{'hidden'}=~/\.$idx\./); unless (($hidden) && (!$seeid)) { my $message=$contrib{$idx.':message'}; $message=~s/\n/\
/g; + $message=&Apache::lontexconvert::msgtexconverted($message); if ($message) { if ($hidden) { $message=''.$message.''; } my $sender='Anonymous'; if ((!$contrib{$idx.':anonymous'}) || ($seeid)) { - $sender=$contrib{$idx.':plainname'}.' ('. + $sender=&Apache::loncommon::aboutmewrapper( + $contrib{$idx.':plainname'}, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}).' ('. $contrib{$idx.':sendername'}.' at '. $contrib{$idx.':senderdomain'}.')'; if ($contrib{$idx.':anonymous'}) { @@ -210,11 +219,16 @@ sub xmlend { } } } - $discussion.='
'; + unless ($discussiononly) { + $discussion.='
'; + } + } + if ($discussiononly) { + $discussion.='

'.$symb.'

'; } } } - return $discussion.''; + return $discussion.($discussiononly?'':''); } sub tokeninputfield { @@ -332,7 +346,8 @@ sub registerurl { my $target = shift; my $result = ''; if ($target eq 'edit') { - $result .="\n"; } @@ -537,6 +552,22 @@ sub htmlclean { return $output; } +sub latex_special_symbols { + my ($current_token,$stack,$parstack)=@_; + $current_token=~s/\\/\\char92 /g; + $current_token=~s/\^/\\char94 /g; + $current_token=~s/\~/\\char126 /g; + $current_token=~s/(&[^a-z#])/\\$1/g; + $current_token=~s/([^&]\#)/\\$1/g; + $current_token=~s/(\$|_|{|})/\\$1/g; + $current_token=~s/\\char92 /\\texttt{\\char92}/g; + $current_token=~s/>/\$>\$/g; #more + $current_token=~s/get_token) { if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { if ($metamode<1) { - if ($target eq 'tex') { - my @temp_array = @$stack; - if ($temp_array[-1] ne 'm') { - if ($temp_array[-1] ne 'tt') { - if ($token->[1]=~m/\^/) {$token->[1]=~s/\^/\\verb|\^|/g;} - } else { - if ($token->[1]=~m/\^/) {$token->[1]=~s/\^/}\\verb|\^|{/g;} - } - if ($token->[1]=~m/>/) {$token->[1]=~s/>/\$>\$/g;} - if ($token->[1]=~m/[1]=~s/[1]; + if ($token->[0] eq 'C' && $target eq 'tex') { + $text = '%'.$text; + $text =~ s/[\n\r]//g; } - $result.=$token->[1]; + $result.=$text; } } elsif ($token->[0] eq 'PI') { if ($metamode<1) { @@ -621,6 +645,12 @@ sub inner_xmlparse { $result= &Apache::run::evaluate($result,$safeeval,''); } } + if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { + if ($target eq 'tex') { + $result=&latex_special_symbols($result,$stack,$parstack); + } + } + # Encode any high ASCII characters if (!$Apache::lonxml::prevent_entity_encode) { $result=&HTML::Entities::encode($result,"\200-\377"); @@ -747,13 +777,13 @@ sub callsub { } if (!$deleted) { if ($space) { - #&Apache::lonxml::debug("Calling sub $sub in $space $metamode"); + &Apache::lonxml::debug("Calling sub $sub in $space $metamode"); $sub1="$space\:\:$sub"; ($currentstring,$nodefault) = &$sub1($target,$token,$tagstack, $parstack,$parser,$safeeval, $style); } else { - #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode"); + &Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode"); if ($metamode <1) { if (defined($token->[4]) && ($metamode < 1)) { $currentstring = $token->[4]; @@ -946,6 +976,7 @@ sub decreasedepth { } sub get_all_text_unbalanced { +#there is a copy of this in lonpublisher.pm my($tag,$pars)= @_; my $token; my $result='';