--- loncom/xml/lonxml.pm 2002/01/17 17:42:34 1.149 +++ loncom/xml/lonxml.pm 2002/01/30 16:04:04 1.151 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.149 2002/01/17 17:42:34 albertel Exp $ +# $Id: lonxml.pm,v 1.151 2002/01/30 16:04:04 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -463,7 +463,7 @@ sub xmlparse { ($target, my @tenta) = split('&&',$target); - my @stack = (); + my @stack = (); my @parstack = (); &initdepth; @@ -533,8 +533,14 @@ sub inner_xmlparse { } elsif ($token->[0] eq 'E') { #clear out any tags that didn't end while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) { - &Apache::lonxml::warning('Missing tag </'.$$stack['-1'].'> in file'); - &end_tag($stack,$parstack,$token); + my $lasttag=$$stack[-1]; + if ($token->[1] =~ /^$lasttag$/i) { + &Apache::lonxml::warning('Using tag </'.$token->[1].'> as end tag to <'.$$stack[-1].'>'); + last; + } else { + &Apache::lonxml::warning('Found tag </'.$$stack[-1].'> when looking for </'.$token->[1].'> in file'); + &end_tag($stack,$parstack,$token); + } } if (exists($$style_for_target{'/'."$token->[1]"})) { @@ -613,10 +619,16 @@ sub recurse { $safeeval, $style_for_target); } elsif ($tokenpat->[0] eq 'E') { #clear out any tags that didn't end - while ($tokenpat->[1] ne $innerstack[$#innerstack] + while ($tokenpat->[1] ne $innerstack[$#innerstack] && ($#innerstack > -1)) { - &Apache::lonxml::warning('Missing tag </'.$innerstack['-1'].'> in style'); - &end_tag(\@innerstack,\@innerparstack,$tokenpat); + my $lasttag=$innerstack[-1]; + if ($tokenpat->[1] =~ /^$lasttag$/i) { + &Apache::lonxml::warning('Using tag </'.$tokenpat->[1].'> as end tag to <'.$innerstack[-1].'>'); + last; + } else { + &Apache::lonxml::warning('Found tag </'.$innerstack[-1].'> when looking for </'.$tokenpat->[1].'> in file'); + &end_tag(\@innerstack,\@innerparstack,$tokenpat); + } } $partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat, \@innerstack, \@innerparstack, \@pat, @@ -885,10 +897,10 @@ sub get_all_text { } elsif ($token->[0] eq 'PI') { $result.=$token->[2]; } elsif ($token->[0] eq 'S') { - if ($token->[1] eq $tag) { $depth++; } + if ($token->[1] =~ /^$tag$/i) { $depth++; } $result.=$token->[4]; } elsif ($token->[0] eq 'E') { - if ( $token->[1] eq $tag) { $depth--; } + if ( $token->[1] =~ /^$tag$/i) { $depth--; } #skip sending back the last end tag if ($depth > -1) { $result.=$token->[2]; } else { $pars->unget_token($token); @@ -903,7 +915,7 @@ sub get_all_text { } elsif ($token->[0] eq 'PI') { $result.=$token->[2]; } elsif ($token->[0] eq 'S') { - if ( $token->[1] eq $tag) { + if ( $token->[1] =~ /^$tag$/i) { $pars->unget_token($token); last; } else { $result.=$token->[4]; @@ -936,7 +948,7 @@ sub parstring { foreach (@{$token->[3]}) { unless ($_=~/\W/) { my $val=$token->[2]->{$_}; - $val =~ s/([\%\@\\])/\\$1/g; + $val =~ s/([\%\@\\\"])/\\$1/g; #if ($val =~ m/^[\%\@]/) { $val="\\".$val; } $temp .= "my \$$_=\"$val\";" } @@ -1016,10 +1028,8 @@ sub storefile { } } -sub inserteditinfo { - my ($result,$filecontents)=@_; - unless ($filecontents) { - $filecontents=(< @@ -1033,8 +1043,12 @@ sub inserteditinfo { </body> </html> SIMPLECONTENT - } + return $filecontents; +} + +sub inserteditinfo { + my ($result,$filecontents)=@_; $filecontents =~ s:</textarea>:</textarea>:ig; # my $editheader='<a href="#editsection">Edit below</a><hr />'; my $editfooter=(<<ENDFOOTER); @@ -1097,6 +1111,10 @@ sub handler { </html> ENDNOTFOUND $filecontents=''; + if ($ENV{'request.state'} ne 'published') { + $filecontents=&createnewhtml(); + $ENV{'form.showmode'}='Edit'; #force edit mode + } } else { unless ($ENV{'request.state'} eq 'published') { if ($ENV{'form.attemptclean'}) {