version 1.1, 2004/07/22 16:17:43
|
version 1.3, 2004/07/22 20:19:20
|
Line 33 package Apache::lonspeller;
|
Line 33 package Apache::lonspeller;
|
use Text::Aspell; |
use Text::Aspell; |
use Apache::lonlocal; |
use Apache::lonlocal; |
use strict; |
use strict; |
|
my $speller; |
|
|
sub getspeller { |
sub markeduptext { |
my $speller = Text::Aspell->new; |
my $input=shift; |
$speller->set_option('lang','en_US'); |
my $output=''; |
$speller->set_option('sug-mode','fast'); |
foreach my $word (split(/\W+/,$input)) { |
return $speller; |
if ($speller->check($word)) { |
|
$output.=$word.' '; |
|
} else { |
|
my $suggestions=join(' ',$speller->suggest($word)); |
|
&Apache::lonnet::logthis($suggestions); |
|
$suggestions=~s/\'/\\\'/gs; |
|
if ($suggestions) { |
|
$output.='<a href="javascript:alert('."'". |
|
$suggestions."');". |
|
'">'; |
|
} |
|
$output.='<font color="red">'.$word.'</font>'; |
|
if ($suggestions) { $output.='</a>'; } |
|
$output.=' '; |
|
} |
|
} |
|
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 { |
|
&initspeller(); |
} |
} |
|
|
1; |
1; |