Diff for /loncom/interface/lonspeller.pm between versions 1.2 and 1.5

version 1.2, 2004/07/22 19:43:46 version 1.5, 2004/07/23 19:47:57
Line 30 Line 30
   
 package Apache::lonspeller;  package Apache::lonspeller;
   
   use Apache::Constants qw(:common);
 use Text::Aspell;  use Text::Aspell;
 use Apache::lonlocal;  use Apache::lonlocal;
   use HTML::LCParser;
 use strict;  use strict;
   
 my $speller;  my $speller;
   
 sub markeduptext {  sub spellcheck_language {
       if ($ENV{'form.lang'}) { return $ENV{'form.lang'}; }
       if (&mt('spellcheck_lang') ne 'spellcheck_lang') {
    return &mt('spellcheck_lang');
       }
       return 'en_US';
   }
   
   sub set_language {
       my $lang=&spellcheck_language();
       $speller->set_option('lang',$lang);
   }
   
   sub textsection {
     my $input=shift;      my $input=shift;
     my $output='';      my $output='';
       &set_language();
     foreach my $word (split(/\W+/,$input)) {      foreach my $word (split(/\W+/,$input)) {
  if ($speller->check($word)) {   if ($speller->check($word)) {
     $output.=$word.' ';      $output.=$word.' ';
Line 58  sub markeduptext { Line 75  sub markeduptext {
     return $output;      return $output;
 }  }
   
   
   sub markeduptext {
       my $input=shift;
       my $output='';
       my $parser=HTML::LCParser->new(\$input);
       my $token;
       while ($token=$parser->get_token) {
    if ($token->[0] eq 'T') {
       $output.=&textsection($token->[1]);
    } elsif ($token->[0] eq 'S') {
       $output.=$token->[4];
       if ($token->[1] eq 'm') {
    $output.=$parser->get_text('/m');
       }
    } elsif ($token->[0] eq 'E') {
       $output.=$token->[2];
    }
       }
       return $output;
   }
   
   sub initspeller {
       unless (defined($speller)) {
    $speller = Text::Aspell->new;
    $speller->set_option('lang','en_US');
    $speller->set_option('sug-mode','fast');
       }
   }
   
   sub handler {
       my $r = shift;
       &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;
       return OK if $r->header_only;
   
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
   
       &initspeller();
       $r->print('<html><head><title>'.
         &mt('Spell Checker').
         '</title></head><body bgcolor="#DDDDDD">'.
         &markeduptext($ENV{'form.text'}).
         '</body></html>');
       return OK;
   }
   
 BEGIN {  BEGIN {
     $speller = Text::Aspell->new;      &initspeller();
     $speller->set_option('lang','en_US');  
     $speller->set_option('sug-mode','fast');  
 #    $speller->set_option('mode','sgml');  
 }  }
   
 1;  1;

Removed from v.1.2  
changed lines
  Added in v.1.5


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