[LON-CAPA-cvs] cvs: loncom /interface lonspeller.pm
www
lon-capa-cvs@mail.lon-capa.org
Thu, 22 Jul 2004 19:43:47 -0000
www Thu Jul 22 15:43:47 2004 EDT
Modified files:
/loncom/interface lonspeller.pm
Log:
Does spell checking, marks wrong words red, underlines words with suggestions
Index: loncom/interface/lonspeller.pm
diff -u loncom/interface/lonspeller.pm:1.1 loncom/interface/lonspeller.pm:1.2
--- loncom/interface/lonspeller.pm:1.1 Thu Jul 22 12:17:43 2004
+++ loncom/interface/lonspeller.pm Thu Jul 22 15:43:46 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Interface routines for Aspell
#
-# $Id: lonspeller.pm,v 1.1 2004/07/22 16:17:43 www Exp $
+# $Id: lonspeller.pm,v 1.2 2004/07/22 19:43:46 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,12 +33,36 @@
use Text::Aspell;
use Apache::lonlocal;
use strict;
+my $speller;
-sub getspeller {
- my $speller = Text::Aspell->new;
+sub markeduptext {
+ my $input=shift;
+ my $output='';
+ foreach my $word (split(/\W+/,$input)) {
+ 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;
+}
+
+BEGIN {
+ $speller = Text::Aspell->new;
$speller->set_option('lang','en_US');
$speller->set_option('sug-mode','fast');
- return $speller;
+# $speller->set_option('mode','sgml');
}
1;