[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm /xml lonxml.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 11 Aug 2003 20:05:53 -0000
This is a MIME encoded message
--albertel1060632353
Content-Type: text/plain
albertel Mon Aug 11 16:05:53 2003 EDT
Modified files:
/loncom/xml lonxml.pm
/loncom/homework structuretags.pm
Log:
- modifying get_all_text to take a $style arg
- using the $style to take a look in the end tag definitons to see if
the getted tag is ended in there
- modifying <block>, <languageblock> and <instructorcomment> to
pass style along
--albertel1060632353
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20030811160553.txt"
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.269 loncom/xml/lonxml.pm:1.270
--- loncom/xml/lonxml.pm:1.269 Wed Aug 6 13:00:30 2003
+++ loncom/xml/lonxml.pm Mon Aug 11 16:05:53 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.269 2003/08/06 17:00:30 albertel Exp $
+# $Id: lonxml.pm,v 1.270 2003/08/11 20:05:53 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -952,83 +952,105 @@
}
sub get_all_text {
- my($tag,$pars)= @_;
- &Apache::lonxml::debug("Got a ".ref($pars));
- my $gotfullstack=1;
- if (ref($pars) ne 'ARRAY') {
- $gotfullstack=0;
- $pars=[$pars];
- }
- my $depth=0;
- my $token;
- my $result='';
- if ( $tag =~ m:^/: ) {
- my $tag=substr($tag,1);
- #&Apache::lonxml::debug("have:$tag:");
- my $top_empty=0;
- while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
- while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
- #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
- if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
- $result.=$token->[1];
- } elsif ($token->[0] eq 'PI') {
- $result.=$token->[2];
- } elsif ($token->[0] eq 'S') {
- if ($token->[1] =~ /^$tag$/i) { $depth++; }
- $result.=$token->[4];
- } elsif ($token->[0] eq 'E') {
- if ( $token->[1] =~ /^$tag$/i) { $depth--; }
- #skip sending back the last end tag
- if ($depth > -1) { $result.=$token->[2]; } else {
- $$pars[-1]->unget_token($token);
- }
- }
- }
- if (($depth >=0) && ($#$pars == 0) ) { $top_empty=1; }
- if (($depth >=0) && ($#$pars > 0) ) {
- pop(@$pars);
- pop(@Apache::lonxml::pwd);
- }
- }
- if ($top_empty && $depth >= 0) {
- #never found the end tag ran out of text, throw error send back blank
- &error('Never found end tag for <'.$tag.'>');
- if ($gotfullstack) {
- my $newstring='</'.$tag.'>'.$result;
- &Apache::lonxml::newparser($pars,\$newstring);
- }
- $result='';
- }
- } else {
- while ($#$pars > -1) {
- while ($token = $$pars[-1]->get_token) {
- #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
- if (($token->[0] eq 'T')||($token->[0] eq 'C')||
- ($token->[0] eq 'D')) {
- $result.=$token->[1];
- } elsif ($token->[0] eq 'PI') {
- $result.=$token->[2];
- } elsif ($token->[0] eq 'S') {
- if ( $token->[1] =~ /^$tag$/i) {
- $$pars[-1]->unget_token($token); last;
- } else {
- $result.=$token->[4];
- }
- } elsif ($token->[0] eq 'E') {
- $result.=$token->[2];
- }
- }
- if (($#$pars > 0) ) {
- pop(@$pars);
- pop(@Apache::lonxml::pwd);
- } else { last; }
- }
- }
- if ($result =~ m|<LONCAPA_INTERNAL_TURN_STYLE_ON />|) {
- $Apache::lonxml::usestyle=1;
- }
- #&Apache::lonxml::debug("Exit:$result:");
- return $result
+ my($tag,$pars,$style)= @_;
+ &Apache::lonxml::debug("Got a ".ref($pars));
+ my $gotfullstack=1;
+ if (ref($pars) ne 'ARRAY') {
+ $gotfullstack=0;
+ $pars=[$pars];
+ }
+ &Apache::lonxml::debug("Got a ".ref($style));
+ if (ref($style) ne 'HASH') {
+ $style={};
+ } else {
+ &Apache::lonhomework::showhash(%$style);
+ }
+ my $depth=0;
+ my $token;
+ my $result='';
+ if ( $tag =~ m:^/: ) {
+ my $tag=substr($tag,1);
+ #&Apache::lonxml::debug("have:$tag:");
+ my $top_empty=0;
+ while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
+ while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
+ #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
+ if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
+ $result.=$token->[1];
+ } elsif ($token->[0] eq 'PI') {
+ $result.=$token->[2];
+ } elsif ($token->[0] eq 'S') {
+ if ($token->[1] =~ /^$tag$/i) { $depth++; }
+ if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/i) { $Apache::lonxml::usestyle=1; }
+ if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/i) { $Apache::lonxml::usestyle=0; }
+ $result.=$token->[4];
+ } elsif ($token->[0] eq 'E') {
+ if ( $token->[1] =~ /^$tag$/i) { $depth--; }
+ #skip sending back the last end tag
+ if ($depth == 0 && exists($$style{'/'.$token->[1]})) {
+ my $string=
+ '<LONCAPA_INTERNAL_TURN_STYLE_OFF end="yes" />'.
+ $$style{'/'.$token->[1]}.
+ $token->[2].
+ '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
+ &Apache::lonxml::newparser($pars,\$string);
+ #&Apache::lonxml::debug("reParsing $string");
+ next;
+ }
+ if ($depth > -1) {
+ $result.=$token->[2];
+ } else {
+ $$pars[-1]->unget_token($token);
+ }
+ }
+ }
+ if (($depth >=0) && ($#$pars == 0) ) { $top_empty=1; }
+ if (($depth >=0) && ($#$pars > 0) ) {
+ pop(@$pars);
+ pop(@Apache::lonxml::pwd);
+ }
+ }
+ if ($top_empty && $depth >= 0) {
+ #never found the end tag ran out of text, throw error send back blank
+ &error('Never found end tag for <'.$tag.
+ '> current string <pre>'.
+ &HTML::Entities::encode($result).
+ '</pre>');
+ if ($gotfullstack) {
+ my $newstring='</'.$tag.'>'.$result;
+ &Apache::lonxml::newparser($pars,\$newstring);
+ }
+ $result='';
+ }
+ } else {
+ while ($#$pars > -1) {
+ while ($token = $$pars[-1]->get_token) {
+ #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
+ if (($token->[0] eq 'T')||($token->[0] eq 'C')||
+ ($token->[0] eq 'D')) {
+ $result.=$token->[1];
+ } elsif ($token->[0] eq 'PI') {
+ $result.=$token->[2];
+ } elsif ($token->[0] eq 'S') {
+ if ( $token->[1] =~ /^$tag$/i) {
+ $$pars[-1]->unget_token($token); last;
+ } else {
+ $result.=$token->[4];
+ }
+ if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/i) { $Apache::lonxml::usestyle=1; }
+ if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/i) { $Apache::lonxml::usestyle=0; }
+ } elsif ($token->[0] eq 'E') {
+ $result.=$token->[2];
+ }
+ }
+ if (($#$pars > 0) ) {
+ pop(@$pars);
+ pop(@Apache::lonxml::pwd);
+ } else { last; }
+ }
+ }
+ #&Apache::lonxml::debug("Exit:$result:");
+ return $result
}
sub newparser {
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.200 loncom/homework/structuretags.pm:1.201
--- loncom/homework/structuretags.pm:1.200 Mon Aug 4 18:40:03 2003
+++ loncom/homework/structuretags.pm Mon Aug 11 16:05:53 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.200 2003/08/04 22:40:03 albertel Exp $
+# $Id: structuretags.pm,v 1.201 2003/08/11 20:05:53 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -625,14 +625,14 @@
}
sub start_block {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
$target eq 'tex' || $target eq 'analyze') {
my $code = $token->[2]->{'condition'};
- if ($code) {
+ if (defined($code)) {
if (!$Apache::lonxml::default_homework_loaded) {
&Apache::lonxml::default_homework_load($safeeval);
}
@@ -642,7 +642,7 @@
$result='1';
}
if ( ! $result ) {
- my $skip=&Apache::lonxml::get_all_text("/block",$parser);
+ my $skip=&Apache::lonxml::get_all_text("/block",$parser,$style);
&Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
}
$result='';
@@ -669,13 +669,33 @@
}
sub start_languageblock {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
$target eq 'tex' || $target eq 'analyze') {
- &Apache::lonxml::startredirection();
+ my $include = $token->[2]->{'include'};
+ my $exclude = $token->[2]->{'exclude'};
+ my %languages=&Apache::loncommon::display_languages();
+ $result='1';
+ if ($include) {
+ $result='';
+ foreach (split(/\,/,$include)) {
+ if ($languages{$_}) { $result='1'; }
+ }
+ }
+ if ($exclude) {
+ foreach (split(/\,/,$exclude)) {
+ if ($languages{$_}) { $result='0'; }
+ }
+ }
+ if ( ! $result ) {
+ my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser,
+ $style);
+ &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
+ }
+ $result='';
} elsif ($target eq 'edit') {
$result .=&Apache::edit::tag_start($target,$token);
$result .=&Apache::edit::text_arg('Include Language:','include',
@@ -695,38 +715,14 @@
sub end_languageblock {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result;
-
- if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
- $target eq 'tex' || $target eq 'analyze') {
- my $text=&Apache::lonxml::endredirection();
- my $include= &Apache::lonxml::get_param('include',$parstack,$safeeval);
- my $exclude= &Apache::lonxml::get_param('exclude',$parstack,$safeeval);
- my %languages=&Apache::loncommon::display_languages();
- $result='1';
- if ($include) {
- $result='';
- foreach (split(/\,/,$include)) {
- if ($languages{$_}) { $result='1'; }
- }
- }
- if ($exclude) {
- foreach (split(/\,/,$exclude)) {
- if ($languages{$_}) { $result='0'; }
- }
- }
- if ( ! $result ) {
- $result='';
- } else {
- $result=$text;
- }
- } elsif ($target eq "edit") {
+ if ($target eq "edit") {
$result.= &Apache::edit::tag_end($target,$token,'');
}
return $result;
}
sub start_instructorcomment {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
@@ -734,7 +730,8 @@
$target eq 'tex' || $target eq 'analyze') {
$result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/);
if ( ! $result ) {
- my $skip=&Apache::lonxml::get_all_text("/instructorcomment",$parser);
+ my $skip=&Apache::lonxml::get_all_text("/instructorcomment",
+ $parser,$style);
&Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
}
$result='';
--albertel1060632353--