--- loncom/xml/lonxml.pm	2015/03/11 13:10:56	1.531.2.18
+++ loncom/xml/lonxml.pm	2016/08/05 20:57:58	1.531.2.20
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.531.2.18 2015/03/11 13:10:56 raeburn Exp $
+# $Id: lonxml.pm,v 1.531.2.20 2016/08/05 20:57:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -463,6 +463,8 @@ sub inner_xmlparse {
   my $result;
   my $token;
   my $dontpop=0;
+  my $lastdontpop;
+  my $lastendtag;
   my $startredirection = $Apache::lonxml::redirection;
   while ( $#$pars > -1 ) {
     while ($token = $$pars['-1']->get_token) {
@@ -558,17 +560,29 @@ sub inner_xmlparse {
       }
       $result = '';
 
-      if ($token->[0] eq 'E' && !$dontpop) {
-	&end_tag($stack,$parstack,$token);
+      if ($token->[0] eq 'E') {
+          if ($dontpop) {
+              $lastdontpop = $token;
+          } else {
+              $lastendtag = $token->[1];
+              &end_tag($stack,$parstack,$token);
+          }
       }
       $dontpop=0;
-    }	
+    }
     if ($#$pars > -1) {
 	pop @$pars;
 	pop @Apache::lonxml::pwd;
     }
   }
 
+  if (($#$stack == 0) && ($stack->[0] eq 'physnet') && ($target eq 'web') &&
+      ($lastendtag eq 'LONCAPA_INTERNAL_TURN_STYLE_ON')) {
+       if ((ref($lastdontpop) eq 'ARRAY') && ($lastdontpop->[1] eq 'physnet')) {
+           &end_tag($stack,$parstack,$lastdontpop);
+       }
+   }
+
   # if ($target eq 'meta') {
   #   $finaloutput.=&endredirection;
   # }
@@ -1555,13 +1569,15 @@ SIMPLECONTENT
 
 sub verify_html {
     my ($filecontents)=@_;
-    my ($is_html,$is_xml);
+    my ($is_html,$is_xml,$is_physnet);
     if ($filecontents =~/(?:\<|\&lt\;)\?xml[^\<]*\?(?:\>|\&gt\;)/is) {
         $is_xml = 1;
     } elsif ($filecontents =~/(?:\<|\&lt\;)html(?:\s+[^\<]+|\s*)(?:\>|\&gt\;)/is) {
         $is_html = 1;
+    } elsif ($filecontents =~/(?:\<|\&lt\;)physnet[^\<]*(?:\>|\&gt\;)/is) {
+        $is_physnet = 1;
     }
-    unless ($is_xml || $is_html) {
+    unless ($is_xml || $is_html || $is_physnet) {
         return &mt('File does not have [_1] or [_2] starting tag','&lt;html&gt;','&lt;?xml ?&gt;');
     }
     if ($is_html) {
@@ -1607,7 +1623,6 @@ sub renderingoptions {
                (''        => '',
                 'tth'     => 'tth (TeX to HTML)',
                 'MathJax' => 'MathJax',
-  		'jsMath'  => 'jsMath',
                 'mimetex' => 'mimetex (Convert to Images)')}).
      '</span>';
     return $output;