--- loncom/xml/londefdef.pm	2001/01/12 20:38:05	1.16
+++ loncom/xml/londefdef.pm	2001/11/06 00:02:25	1.33
@@ -2,7 +2,7 @@
 # Tags Default Definition Module 
 #
 # last modified 06/26/00 by Alexander Sakharuk
-# 11/6,11/30 Gerd Kortemeyer
+# 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer
 
 package Apache::londefdef; 
 
@@ -11,56 +11,59 @@ use Apache::lonxml;
 
 sub BEGIN {
 
-    &Apache::lonxml::register('Apache::londefdef',('m','html','head','map','applet','select','option','input','textarea','form','meta','title','body','center','b','strong','table','dt','h1','h2','h3','h4','h5','h6','cite','i','address','dd','dl','dir','ol','ul','menu','dfn','kbd','tt','code','em','q','p','br','big','small','basefont','font','s','sub','strike','sup','hr','a','li','u','output','param','applet','img','embed','tr','td'));
+    &Apache::lonxml::register('Apache::londefdef',('m','html','head','map','select','option','input','textarea','form','meta','title','body','center','b','strong','table','dt','h1','h2','h3','h4','h5','h6','cite','i','address','dd','dl','dir','ol','ul','menu','dfn','kbd','tt','code','em','q','p','br','big','small','basefont','font','s','sub','strike','sup','hr','a','li','u','output','param','applet','img','embed','tr','td','allow','frameset'));
 
 }
 
 #===================================================================== TAG SUBROUTINES
 #-- <output>
-        sub start_output {
- 	    my ($target,$token) = @_;
-            $Apache::lonxml::textredirection = 1; 
-            my $result = '';
-            return $result;
-	}
-        sub end_output {
- 	    my ($target,$token) = @_;
-            $Apache::lonxml::textredirection = 0;             
-            my $result = '';
-            return $result;
-	}
+sub start_output {
+  my ($target) = @_;
+  if ($target eq 'meta') { $Apache::lonxml::metamode--; }
+  return '';
+}
+sub end_output {
+  my ($target) = @_;
+  if ($target eq 'meta') { $Apache::lonxml::metamode++; }
+  return '';
+}
 #-- <m> tag
-        sub start_m {
-	    my ($target,$token,$parstack,$parser) = @_;
-            my $currentstring = '';
-            if ($target eq 'web') {
-		my $inside = &Apache::lonxml::get_all_text("/m",$$parser[$#$parser]); 
-                $inside ='\\documentstyle{article}'.$inside;
-#          &Apache::lonxml::debug($inside);
-                $currentstring = &Apache::lontexconvert::converted(\$inside);
-#          &Apache::lonxml::debug($currentstring);
-
-	    } elsif ($target eq 'tex') {
-              $currentstring = "";
-            }
-	   return $currentstring;
-	}
-        sub end_m {
-	    my ($target,$token) = @_;
-            my $currentstring = '';
-            if ($target eq 'web') {
-            } elsif ($target eq 'tex') {
-              $currentstring = "";
-	    } elsif ($target eq 'meta') {
-            }
-	   return $currentstring;
-	}
+sub start_m {
+  my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
+  my $currentstring = '';
+  if ($target eq 'web') {
+    my $inside = &Apache::lonxml::get_all_text("/m",$$parser[-1]);
+    $inside ='\\documentstyle{article}'.$inside;
+    #&Apache::lonxml::debug("M is starting with:$inside:");
+    my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
+    if ($eval eq 'on') {
+      $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
+      #&Apache::lonxml::debug("M is evaulated to:$inside:");
+    }
+    $currentstring = &Apache::lontexconvert::converted(\$inside);
+    #&Apache::lonxml::debug("M is ends with:$currentstring:");
+  } elsif ($target eq 'tex') {
+    $currentstring = "";
+  }
+  return $currentstring;
+}
+sub end_m {
+  my ($target,$token) = @_;
+  my $currentstring = '';
+  if ($target eq 'web') {
+  } elsif ($target eq 'tex') {
+    $currentstring = "";
+  } elsif ($target eq 'meta') {
+  }
+  return $currentstring;
+}
 #-------------------------------------------------------------------------- <html> tag    
       sub start_html {
 	    my ($target,$token) = @_;
             my $currentstring = '';
             if ($target eq 'web') {
-              $currentstring = $token->[4];     
+              $currentstring = &Apache::lonxml::xmlbegin().
+                               &Apache::lonxml::fontsettings();     
 	    } 
 	   return $currentstring;
 	}
@@ -68,7 +71,7 @@ sub BEGIN {
 	    my ($target,$token) = @_;
             my $currentstring = '';
             if ($target eq 'web') {
-              $currentstring = $token->[2];    
+		$currentstring = &Apache::lonxml::xmlend();
             } 
 	   return $currentstring;
 	}
@@ -85,7 +88,8 @@ sub BEGIN {
 	    my ($target,$token) = @_;
             my $currentstring = '';
             if ($target eq 'web') {
-              $currentstring = $token->[2];    
+              $currentstring = &Apache::lonxml::registerurl().
+                               $token->[2];    
             } 
 	   return $currentstring;
 	}
@@ -106,23 +110,7 @@ sub BEGIN {
             } 
 	   return $currentstring;
 	}
-#------------------------------------------------------------------------ <applet> tag
-      sub start_applet {
-	    my ($target,$token) = @_;
-            my $currentstring = '';
-            if ($target eq 'web') {
-              $currentstring = $token->[4];     
-	    } 
-	   return $currentstring;
-	}
-        sub end_applet {
-	    my ($target,$token) = @_;
-            my $currentstring = '';
-            if ($target eq 'web') {
-              $currentstring = $token->[2];    
-            } 
-	   return $currentstring;
-	}
+
 #------------------------------------------------------------------------ <select> tag
       sub start_select {
 	    my ($target,$token) = @_;
@@ -235,15 +223,18 @@ sub BEGIN {
 	}
 #-------------------------------------------------------------------------- <meta> tag
       sub start_meta {
-	    my ($target,$token) = @_;
+	    my ($target,$token,$tagstack,$parstack,$parser) = @_;
             my $currentstring = '';
-	    &Apache::lonxml::debug("In meta");
             if ($target eq 'web') {
-	      &Apache::lonxml::debug("In meta2");
-              $currentstring = $token->[4];     
+	      my $args='';
+	      if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
+	      if ($args eq '') {
+		&Apache::lonxml::get_all_text("/meta",$$parser[$#$parser]);
+	      } else {
+		$currentstring = $token->[4];
+	      }
 	    }
             if ($target eq 'meta') {
-	      &Apache::lonxml::debug("In meta3");
 		unless ($token->[2]->{'http-equiv'}) {
 		    my $name=$token->[2]->{'name'};
                     $name=~tr/A-Z/a-z/;
@@ -255,24 +246,52 @@ sub BEGIN {
 		    }
                 }
 	    }
-	    &Apache::lonxml::debug("send back $currentstring");
-	   return $currentstring;
-	}
-        sub end_meta {
-	    my ($target,$token) = @_;
-            my $currentstring = '';
-            if ($target eq 'web') {
-              $currentstring = $token->[2];    
-            } 
 	   return $currentstring;
 	}
+      sub end_meta {
+	my ($target,$token,$tagstack,$parstack,$parser) = @_;
+	my $currentstring = '';
+	if ($target eq 'web') {
+	  my $args='';
+	  if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
+	  if ($args ne '') {
+	    $currentstring = $token->[4];
+	  }
+	} 
+	return $currentstring;
+      }
 #-------------------------------------------------------------------------- <body> tag
         sub start_body {
 	    my ($target,$token) = @_;
             my $currentstring = '';
             if ($target eq 'web') {
-              $currentstring = $token->[4];     
-	    } elsif ($target eq 'tex') {
+	      if (!$Apache::lonxml::registered) {
+		$currentstring.='<head>'.&Apache::lonxml::registerurl().'</head>';
+	      }
+	      my $onLoad='';
+	      foreach my $key (keys(%{$token->[2]})) {
+		if ($key =~ /^onload$/i) {
+		  $onLoad.=$token->[2]->{$key}.';';
+		  delete($token->[2]->{$key});
+		}
+	      }
+	      $token->[2]->{'onLoad'}=$onLoad.&Apache::lonxml::loadevents();
+	      my $onUnload='';
+	      foreach my $key (keys(%{$token->[2]})) {
+		if ($key =~ /^onunload$/i) {
+		  $onUnload.=$token->[2]->{$key}.';';
+		  delete($token->[2]->{$key});
+		}
+	      }
+	      $token->[2]->{'onUnload'}=$onUnload.
+		&Apache::lonxml::unloadevents();
+
+	      $currentstring .= '<'.$token->[1];
+	      map {
+		$currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
+	      } keys %{$token->[2]};
+	      $currentstring.='>';
+       	    } elsif ($target eq 'tex') {
               $currentstring = " \\begin{document} ";  
 	    } 
 	   return $currentstring;
@@ -295,6 +314,8 @@ sub BEGIN {
               $currentstring = $token->[4];     
 	    } elsif ($target eq 'tex') {
               $currentstring = " \\begin{center} ";  
+	    }  elsif ($target eq 'latexsource') {
+              $currentstring = " \\begin{center} ";  
 	    } 
 	   return $currentstring;
 	}
@@ -305,6 +326,8 @@ sub BEGIN {
               $currentstring = $token->[2];     
 	    } elsif ($target eq 'tex') {
               $currentstring = " \\end{center}";  
+	    }  elsif ($target eq 'latexsource') {
+              $currentstring = " \\end{center}";  
 	    } 
 	   return $currentstring;
 	}
@@ -315,7 +338,9 @@ sub BEGIN {
             if ($target eq 'web') {
               $currentstring = $token->[4];     
 	    } elsif ($target eq 'tex') {
-              $currentstring = " {\\bf ";  
+              $currentstring = " \\textbf{";  
+	    }  elsif ($target eq 'latexsource') {
+              $currentstring = " \\textbf{";  
 	    } 
 	   return $currentstring;
 	}
@@ -326,6 +351,8 @@ sub BEGIN {
               $currentstring = $token->[2];     
 	    } elsif ($target eq 'tex') {
               $currentstring = "}";  
+	    } elsif ($target eq 'latexsource') {
+              $currentstring = "}";  
 	    } 
 	   return $currentstring;
 	}
@@ -336,7 +363,9 @@ sub BEGIN {
             if ($target eq 'web') {
               $currentstring = $token->[4];     
 	    } elsif ($target eq 'tex') {
-              $currentstring = " {\\bf ";  
+              $currentstring = " \\textbf{";  
+	    } elsif ($target eq 'latexsource') {
+              $currentstring = " \\textbf{";  
 	    } 
 	   return $currentstring;
 	}
@@ -348,6 +377,8 @@ sub BEGIN {
               $currentstring = $token->[2];     
 	    } elsif ($target eq 'tex') {
               $currentstring = "}";  
+	    }  elsif ($target eq 'latexsource') {
+              $currentstring = "}";  
 	    } 
 	   return $currentstring;
 	}
@@ -490,7 +521,9 @@ sub BEGIN {
             if ($target eq 'web') {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
-		$currentstring .= "{ \\it ";
+		$currentstring .= "\\textit{";
+	    }  elsif ($target eq 'latexsource') {
+		$currentstring .= "\\textit{";
 	    } 
            return $currentstring;
 	}
@@ -501,6 +534,8 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "}";
+	    }  elsif ($target eq 'latexsource') {
+		$currentstring .= "}";
 	    } 
            return $currentstring;
 	}
@@ -511,7 +546,9 @@ sub BEGIN {
             if ($target eq 'web') {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
-		$currentstring .= "{ \\it ";
+		$currentstring .= "\\textit{";
+	    }  elsif ($target eq 'latexsource') {
+		$currentstring .= "\\textit{";
 	    } 
            return $currentstring;
 	}
@@ -522,6 +559,8 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "}";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "}";
 	    } 
            return $currentstring;
 	}
@@ -532,7 +571,9 @@ sub BEGIN {
             if ($target eq 'web') {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
-		$currentstring .= "{ \\it ";
+		$currentstring .= "\\textit{";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "\\textit{";
 	    } 
            return $currentstring;
 	}
@@ -543,6 +584,8 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "}";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "}";
 	    }
            return $currentstring;
 	}
@@ -553,7 +596,9 @@ sub BEGIN {
             if ($target eq 'web') {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
-		$currentstring .= "{ \\it ";
+		$currentstring .= "\\textit{";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "\\textit{";
 	    } 
            return $currentstring;
 	}
@@ -564,6 +609,8 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "}";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "}";
 	    } 
            return $currentstring;
 	}
@@ -574,7 +621,9 @@ sub BEGIN {
             if ($target eq 'web') {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
-		$currentstring .= "{ \\tt ";
+		$currentstring .= "\\texttt{";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "\\texttt{";
 	    } 
            return $currentstring;
 	}
@@ -585,7 +634,9 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "}";
-	    } 
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "}";
+	    }
            return $currentstring;
 	}
 #---------------------------------------------------------------------------- <kbd> tag
@@ -595,7 +646,9 @@ sub BEGIN {
             if ($target eq 'web') {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
-		$currentstring .= "{ \\tt ";
+		$currentstring .= "\\texttt";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "\\texttt{";
 	    } 
            return $currentstring;
 	}
@@ -606,6 +659,8 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "}";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "}";
 	    } 
            return $currentstring;
 	}
@@ -638,6 +693,8 @@ sub BEGIN {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "\\emph{";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "\\emph{";
 	    } 
            return $currentstring;
 	}
@@ -648,7 +705,9 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "}";
-	    } 
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "}";
+	    }  
            return $currentstring;
 	}
 #----------------------------------------------------------------------------- <q> tag
@@ -658,8 +717,10 @@ sub BEGIN {
             if ($target eq 'web') {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
-		$currentstring .= "{ \\emph ";
-	    } 
+		$currentstring .= "\\emph{";
+	    }  elsif ($target eq 'latexsource') {
+		$currentstring .= "\\emph{";
+	    }
            return $currentstring;
 	}
         sub end_q {
@@ -669,7 +730,9 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "}";
-	    } 
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "}";
+	    }  
            return $currentstring;
 	}
 #----------------------------------------------------------------------------- <p> tag
@@ -680,6 +743,8 @@ sub BEGIN {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "{\\par ";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "{\\par ";
 	    } 
            return $currentstring;
 	}
@@ -689,7 +754,9 @@ sub BEGIN {
             if ($target eq 'web') {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
-	        $currentstring .= " }";
+	        $currentstring .= "}";
+            } elsif ($target eq 'latexsource') {
+	        $currentstring .= "}";
             }
            return $currentstring;
 	}
@@ -701,6 +768,8 @@ sub BEGIN {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "\\\\";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "\\\\";
 	    } 
            return $currentstring;
 	}
@@ -720,7 +789,9 @@ sub BEGIN {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "{\\large ";
-	    } 
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "{\\large ";
+	    }  
            return $currentstring;
 	}
         sub end_big {
@@ -730,6 +801,8 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 	        $currentstring .= " }";
+            } elsif ($target eq 'latexsource') {
+	        $currentstring .= " }";
             }
            return $currentstring;
 	}
@@ -741,6 +814,8 @@ sub BEGIN {
 	       $currentstring .= $token->[4];
 	    } elsif ($target eq 'tex') {
 		$currentstring .= "{\\footnotesize ";
+	    } elsif ($target eq 'latexsource') {
+		$currentstring .= "{\\footnotesize ";
 	    } 
            return $currentstring;
 	}
@@ -751,6 +826,8 @@ sub BEGIN {
 	       $currentstring .= $token->[2];
 	    } elsif ($target eq 'tex') {
 	        $currentstring .= " }";
+            } elsif ($target eq 'latexsource') {
+	        $currentstring .= " }";
             }
            return $currentstring;
 	}
@@ -903,7 +980,7 @@ sub BEGIN {
            return $currentstring;
 	}
         sub end_a {
-	    my ($target,$token,$stackref) = @_;
+	    my ($target,$token,$tagstack,$stackref) = @_;
             my $currentstring = '';
             if ($target eq 'web') {
 	       $currentstring .= $token->[2];
@@ -921,7 +998,7 @@ sub BEGIN {
 	}
 #---------------------------------------------------------------------------- <li> tag
         sub start_li {
-	    my ($target,$token,$stackref) = @_;
+	    my ($target,$token,$tagstack,$stackref) = @_;
             my $currentstring = '';
             if ($target eq 'web') {
               $currentstring = $token->[4];     
@@ -1260,7 +1337,7 @@ sub BEGIN {
                       $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 					     $token->[2]->{'value'};
             }   
-            $Apache::lonxml::extlinks[$Apache::lonxml::extlinks+1]=   
+            $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   
                                         $token->[2]->{'src'};
             my $currentstring = '';
             if ($target eq 'web') {
@@ -1286,7 +1363,7 @@ sub BEGIN {
         sub start_allow {
 	    my ($target,$token) = @_;
 
-            $Apache::lonxml::extlinks[$Apache::lonxml::extlinks+1]=   
+            $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   
                                         $token->[2]->{'src'};
 
 	   return '';
@@ -1295,6 +1372,25 @@ sub BEGIN {
 	   return '';
 	}
 
-
+# ------------------------------------------------------------------------- Frames
+	sub start_frameset {
+	  my ($target,$token) = @_;
+	  my $currentstring = '';
+	  if ($target eq 'web') { 
+	    if (!$Apache::lonxml::registered) {
+	      $currentstring.='<head>'.&Apache::lonxml::registerurl().'</head>';
+	    }
+	    $currentstring .= $token->[4];
+	  }
+	  return $currentstring;
+	}
+        sub end_frameset {
+	  my ($target,$token) = @_;
+	  my $currentstring = '';
+	  if ($target eq 'web') {
+	    $currentstring = $token->[2];
+	  }
+	  return $currentstring;
+	}
 1;
 __END__