[LON-CAPA-cvs] cvs: loncom /interface lonhtmlgateway.pm

faziophi faziophi@source.lon-capa.org
Tue, 04 May 2010 19:45:05 -0000


faziophi		Tue May  4 19:45:05 2010 EDT

  Modified files:              
    /loncom/interface	lonhtmlgateway.pm 
  Log:
  -- Encodes all high-bit (unicode) characters to their XML decimal entity
  in form &#xxxx;.  This fixes problems with unicode characters being
  destroyed when passed through HTML->TeX.
  
  -- Only run &to_convert() when web output, otherwise just create an <m>
  tag which gets handled further down.  This prevents the TeX output
  looking for an image which doesn't exist.
  
  
  
Index: loncom/interface/lonhtmlgateway.pm
diff -u loncom/interface/lonhtmlgateway.pm:1.3 loncom/interface/lonhtmlgateway.pm:1.4
--- loncom/interface/lonhtmlgateway.pm:1.3	Tue Apr 27 20:29:25 2010
+++ loncom/interface/lonhtmlgateway.pm	Tue May  4 19:45:05 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # gateway for html input/output to be properly parsed and handled
 #
-# $Id: lonhtmlgateway.pm,v 1.3 2010/04/27 20:29:25 faziophi Exp $
+# $Id: lonhtmlgateway.pm,v 1.4 2010/05/04 19:45:05 faziophi Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -548,7 +548,9 @@
             if ($self->{target} ne 'tex') {
     	        $output .= &Apache::lontexconvert::smiley($token->[1]);
     	    } else {
-                $output .= $token->[1];
+                my $t = $token->[1];
+                $t =~ s/([^\n\r\t &<>!\#%\(-;=?-~])/num_entity($1)/ge;
+                $output .= $t;
             }
         } elsif ($token->[0] eq 'D' || $token->[0] eq 'C') {
     	    $output .= $token->[1];
@@ -565,7 +567,6 @@
     	    }
     	}
     }
-
     return $output;
 }
 
@@ -637,6 +638,10 @@
     return \@block;
 }
 
+sub num_entity {
+    sprintf "&#x%X;", ord($_[0]);
+}
+
 ##############################################
 ##############################################
 
@@ -735,7 +740,11 @@
 sub parse_m_tag {
     my $self = shift;
     my $input = shift;
-    return &Apache::lontexconvert::to_convert($input, $self->{target});
+    if ($self->{target} ne 'tex') {
+        return &Apache::lontexconvert::to_convert($input, $self->{target});
+    } else {
+        return '<m>'.$input.'</m>';
+    }
 }
 
 sub parse_chem_tag {
@@ -806,7 +815,7 @@
 
 =head1 VERSION
 
-$Id: lonhtmlgateway.pm,v 1.3 2010/04/27 20:29:25 faziophi Exp $
+$Id: lonhtmlgateway.pm,v 1.4 2010/05/04 19:45:05 faziophi Exp $
 
 =cut