File:  [LON-CAPA] / loncom / xml / lontexconvert.pm
Revision 1.28: download - view: text, annotated - select for diffs
Thu Nov 6 15:27:07 2003 UTC (20 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: version_1_1_X, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, HEAD
- tth generates
</font



>

this seems to annoy some sub version of IE.

Thus we remove the whitespace in the end font tag
(BUG#2189)

    1: # The LearningOnline Network with CAPA
    2: # TeX Conversion Module
    3: #
    4: # $Id: lontexconvert.pm,v 1.28 2003/11/06 15:27:07 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson. 
   29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into 
   30: # binary executable programs or libraries distributed by the 
   31: # Michigan State University (the "Licensee"), but any binaries so 
   32: # distributed are hereby licensed only for use in the context
   33: # of a program or computational system for which the Licensee is the 
   34: # primary author or distributor, and which performs substantial 
   35: # additional tasks beyond the translation of (La)TeX into HTML.
   36: # The C source of the Code may not be distributed by the Licensee
   37: # to any other parties under any circumstances.
   38: #
   39: # 05/29/00,05/30,10/11,10/20 Gerd Kortemeyer
   40: # 5/4 Gerd Kortemeyer
   41: 
   42: package Apache::lontexconvert;
   43: 
   44: use strict;
   45: use tth;
   46: use vars qw($errorstring);
   47: use Apache();
   48: use Apache::lonmsg;
   49: use Apache::lonxml;
   50: use Apache::lonmenu;
   51: 
   52: # ====================================================================== Header
   53: 
   54: sub header {
   55:   $errorstring='';
   56:   my $time=time;
   57:   if ($ENV{'browser.mathml'}) {
   58:       &tth::ttminit();
   59:       if ($ENV{'browser.unicode'}) {
   60: 	  &tth::ttmoptions('-L -u1');
   61:       } else {
   62: 	  &tth::ttmoptions('-L -u0');
   63:       }
   64:   } else {
   65:       &tth::tthinit();
   66:       if ($ENV{'browser.unicode'}) {
   67: 	  &tth::tthoptions('-L -u1');
   68:       } else {
   69: 	  &tth::tthoptions('-L -u0');
   70:       }
   71:   }
   72:   return &Apache::lonxml::xmlbegin().
   73:          &Apache::lonxml::fontsettings().
   74:          "\n<head>\n".
   75:          &Apache::lonmenu::registerurl(undef,'tex').
   76: 	 "\n</head>\n";
   77: }
   78: 
   79: # ================================================================== Conversion
   80: 
   81: $Apache::lontexconvert::messedup=0;
   82: sub converted {
   83:   my $texstring=shift;
   84:   my $xmlstring='[UNDISPLAYABLE]';
   85:   if ($Apache::lontexconvert::messedup) {
   86:       return '[TeX Unconverted Due To Previous Errors]';
   87:   }
   88:   eval(<<'ENDCONV');
   89:   {
   90:     local $SIG{SEGV}=sub { $Apache::lontexconvert::messedup=1; die; };
   91:     if ($ENV{'browser.mathml'}) {
   92:       $xmlstring=&tth::ttm($$texstring);
   93:       $xmlstring=~s/\<math\>/\<math xmlns=\"\&mathns\;\"\>/g;
   94:       $xmlstring=~s/\<br\>/\<br\/\>/g;
   95:       $xmlstring=~s/\<p\>/\<p\>\<\/p\>/g;
   96:       $errorstring.=&tth::ttmerror();
   97:     } else {
   98:       $xmlstring=&tth::tth($$texstring);
   99:       $errorstring.=&tth::ttherror();
  100:       $xmlstring=~s-</font(\s*)>-</font>-g;
  101:     }
  102:     $xmlstring=~s/^\s*//;
  103:     $xmlstring=~s/\s*$//;
  104:   }
  105: ENDCONV
  106:   if ($Apache::lontexconvert::messedup || &tth::tthmessedup()) {
  107:       &Apache::lonnet::logthis("Trying to kill myself");
  108:       $Apache::lontexconvert::messedup=1;
  109:       my $request=Apache->request();
  110:       $request->child_terminate();
  111:   }
  112:   return $xmlstring;
  113: }
  114: 
  115: # ====================================================================== Footer
  116: 
  117: sub footer {
  118:   my $xmlstring='';
  119:   if ($ENV{'request.state'} eq 'construct') {
  120:       $xmlstring.='<address>'.$errorstring.'</address>';
  121:   } else {
  122:       &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$errorstring);
  123:   }
  124: # -------------------------------------------------------------------- End Body
  125:   $xmlstring.=&Apache::lonxml::xmlend();
  126:   return $xmlstring;
  127: }
  128: 
  129: # ------------------------------------------------------------ Message display
  130: 
  131: sub to_convert {
  132:     my ($string) = @_;
  133:     $string=~s/\<br\s*\/?\>/ /gs;
  134:     $string=~s/\s/ /gs;
  135:     $string=&HTML::Entities::decode($string);
  136:     return &converted(\$string);
  137: }
  138: 
  139: sub smiley {
  140:    my $expression=shift;
  141:    if ($ENV{'browser.imagesuppress'} eq 'on') { return $expression; }
  142:    my %smileys=('\:\-\)' => 'smiley',
  143:                 '8\-\)'  => 'coolsmile',
  144:                 '8\-(I|\|)'   => 'coolindiff',
  145:                 ':\-(I|\|)'   => 'neutral',
  146:                 '\:\-(o|O|\(\))' => 'shocked',
  147:                 ':\-\('  => 'frowny',
  148:                 '\;\-\)' => 'wink',
  149:                 '\:\-P'  => 'baeh',
  150:                 '\:\-(\\\|\\/)' => 'hrrm',
  151:                 '\:\-D'  => 'bigsmile',
  152:                 '\:\-C'  => 'angry',
  153:                 '\:(\'|\`)\-\(' => 'cry',
  154:                 '\:\-(X|\#)' => 'lipsrsealed',
  155:                 '\:\-S' => 'huh');
  156:    my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
  157:    foreach (keys %smileys) {
  158:       $expression=~s/$_/\<img src="$iconpath\/$smileys{$_}.gif" \/\>/gs; 
  159:    }
  160:    return $expression;
  161: }
  162: 
  163: sub msgtexconverted {
  164:     my $message=shift;
  165: 
  166:     $errorstring='';
  167:     if ($ENV{'browser.mathml'}) {
  168: 	&tth::ttminit();
  169: 	if ($ENV{'browser.unicode'}) {
  170: 	    &tth::ttmoptions('-L -u1');
  171: 	} else {
  172: 	    &tth::ttmoptions('-L -u0');
  173: 	}
  174:     } else {
  175: 	&tth::tthinit();
  176: 	if ($ENV{'browser.unicode'}) {
  177: 	    &tth::tthoptions('-L -u1');
  178: 	} else {
  179: 	    &tth::tthoptions('-L -u0');
  180: 	}
  181:     }
  182:     my $outmessage='';
  183:     my $tex=0;
  184:     foreach (split(/(?:\&lt\;|\<)\/*m\s*(?:\&gt\;|\>)/i,$message)) {
  185: 	if ($tex) {
  186: 	    $outmessage.=&to_convert($_); $tex=0;
  187: 	} else {
  188:             $outmessage.=&smiley($_); $tex=1;
  189: 	}
  190:     }
  191:     if (wantarray) {
  192: 	return ($outmessage,$errorstring);
  193:     } else {
  194: 	return $outmessage.$errorstring;
  195:     }
  196: }
  197: 
  198: 1;
  199: __END__
  200: 
  201: 
  202: 
  203: 
  204: 
  205: 
  206: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>