--- loncom/interface/lonhtmlgateway.pm 2010/04/26 20:45:28 1.1 +++ loncom/interface/lonhtmlgateway.pm 2010/05/24 23:47:22 1.5 @@ -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.1 2010/04/26 20:45:28 faziophi Exp $ +# $Id: lonhtmlgateway.pm,v 1.5 2010/05/24 23:47:22 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -545,8 +545,14 @@ sub process_outgoing_html { my $parser = HTML::LCParser->new(\$input); while (my $token = $parser->get_token()) { if ($token->[0] eq 'T') { - $output .= $token->[1]; - } elsif ($token->[0] eq 'D' || $token->[0] eq 'C') { + if ($self->{target} ne 'tex') { + $output .= &Apache::lontexconvert::smiley($token->[1]); + } else { + 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]; } elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') { $output .= $token->[2]; @@ -561,7 +567,6 @@ sub process_outgoing_html { } } } - return $output; } @@ -633,6 +638,10 @@ sub get_block_level_tags { return \@block; } +sub num_entity { + sprintf "&#x%X;", ord($_[0]); +} + ############################################## ############################################## @@ -709,15 +718,18 @@ sub parse_algebra_tag { # the parser does NOT handle entities, # unlike the general parser; thus we run # the content of this tag through HTML::Entities, - # decoding it first + # decoding it first. we also just get the tex, and + # feed it through as if it were an tag. $input = &HTML::Entities::decode($input); - return &Apache::lontexconvert::algebra($input,$self->{target}); + my $algebra = + &Apache::lontexconvert::algebra($input,'tex',undef,undef,undef,'tth'); + return &parse_m_tag($self, $algebra); } sub parse_mi_tag { my $self = shift; my $input = shift; - return &parse_m_tag($self, '$'.$input.'$'); + return &parse_m_tag($self, '\ensuremath{'.$input.'}'); } sub parse_md_tag { @@ -729,7 +741,11 @@ sub parse_md_tag { 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 ''.$input.''; + } } sub parse_chem_tag { @@ -800,7 +816,7 @@ Phil Fazio =head1 VERSION -$Id: lonhtmlgateway.pm,v 1.1 2010/04/26 20:45:28 faziophi Exp $ +$Id: lonhtmlgateway.pm,v 1.5 2010/05/24 23:47:22 raeburn Exp $ =cut