--- loncom/interface/lonspeller.pm 2004/07/22 20:19:20 1.3 +++ loncom/interface/lonspeller.pm 2004/07/23 19:47:57 1.5 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Interface routines for Aspell # -# $Id: lonspeller.pm,v 1.3 2004/07/22 20:19:20 www Exp $ +# $Id: lonspeller.pm,v 1.5 2004/07/23 19:47:57 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,14 +30,31 @@ package Apache::lonspeller; +use Apache::Constants qw(:common); use Text::Aspell; use Apache::lonlocal; +use HTML::LCParser; use strict; + 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 $output=''; + &set_language(); foreach my $word (split(/\W+/,$input)) { if ($speller->check($word)) { $output.=$word.' '; @@ -56,6 +73,27 @@ sub markeduptext { } } 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 {