[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm

foxr lon-capa-cvs@mail.lon-capa.org
Mon, 11 Jul 2005 10:27:59 -0000


foxr		Mon Jul 11 06:27:59 2005 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Defect 4199 - First crack at an implementation of <div> in printing target
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.279 loncom/xml/londefdef.pm:1.280
--- loncom/xml/londefdef.pm:1.279	Mon Jul 11 05:49:59 2005
+++ loncom/xml/londefdef.pm	Mon Jul 11 06:27:58 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.279 2005/07/11 09:49:59 foxr Exp $
+# $Id: londefdef.pm,v 1.280 2005/07/11 10:27:58 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -1475,12 +1475,44 @@
 }
 
 #-- <div> tag (end tag required)
+{
+
+#  Since div can be nested, the stack below is used
+#  in 'tex' mode to store the ending strings
+#  for the div stack.
+
+    my @div_end_stack;
+
 sub start_div {
-    my ($target,$token) = @_;
+    my ($target,$token, $tagstack, $parstack, $parser, $safeeval) = @_;
     my $currentstring = &end_p();	# Close enclosing para.
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } 
+    if ($target eq 'tex') {
+	# 4 possible alignments: left, right, center, and -missing-.
+
+	my $endstring = '';
+
+	my $align = lc(&Apache::lonxml::get_param('align', $parstack,
+						  $safeeval, undef, 1));
+	if ($align eq 'center') {
+	    $currentstring .= '\begin{center}';
+	    $endstring      = '\end{center}';
+	}
+	elsif ($align eq 'right') {
+	    $currentstring .= '\begin{flushright}';
+	    $endstring     .= '\end{flushright}';
+	} elsif ($align eq 'left') {
+	    $currentstring .= '\begin{flushleft}';
+	    $endstring     = '\end{flushleft}';
+	} else {
+	
+	}
+	$currentstring .= "\n";   # For human readability.
+	$endstring       = "\n$endstring\n"; # For human readability
+	push(@div_end_stack, $endstring);
+    }
     return $currentstring;
 }
 
@@ -1489,9 +1521,14 @@
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring .= $token->[2];
-    } 
+    }
+    if ($target eq 'tex') {
+	my $endstring = pop @div_end_stack;
+	$currentstring .= $endstring;
+    }
     return $currentstring;
 }
+}
 
 #-- <a> tag (end tag required)
 sub start_a {