The early Patch to add spell checking to the HTML Editor

The early Patch to add spell checking to the HTML Editor

by Ludo (Marc Alier) -
Number of replies: 4


Hello as WP1 suggested I'm moving the spell check thread here,

here is an early patch to add a spell checking feature to the moodle's HTML editor.

Current Features:

  • Add's a button in the HTML editor toolbar that invoques a spell checking utility.
  • Only one language

Future work (but I'm gonna need some help):

  • Multiple languages ( as many as dictionaries installed on the server )
  • Binding the dictionary language with the course language or user's language.
  • Activate / deactivate the tool depending on the course and/or  user profile.

Installation instructions.

  1. Download and Install the ASPELL application from the following addresses:
    http://aspell.net/win32/ If you work with windows.
    http://aspell.sourceforge.net If you prefer the UNIX version.
    I use the version 5 (because is more stable and has more dictionaries available).
  2. Download and Install the English dictionary.
  3. The file speller.zip contains a directory called "speller" that must be unzipped into the
    moodle directory.
  4. Edit the file speller/server-scripts/spellchecker.php and:
    #  Change the aspell_prog variable to point to the aspell.exe file
    # in your system
    # is VERY IMPORTANT that you leave the double cuotes insithe the simple ones
    # like this $aspell_prog = '"c:\usr\Aspell\bin\aspell.exe"';
  5. Replace The File "weblib.php" in the "lib" directory. ( But make a backup first tímido )

Now you only have to access to your moodle site and use the HTML editor to post something. You'll find a new button.


About aspell:

About the C++ compilation: I use ASPELL on windows XP and I did install the binaty version wich you can dowloada here:

Latest Version: GNU Aspell-0.50.3 (win32)

Full installer (Released Dec 22, 2002)

And the precompiled English dictionary is here

English aspell-en-0.50-2-3.exe 2.3 M Kevin Atkinson

(both links taken from http://aspell.net/win32)

If you work with linux or another unix OS:

Aspell is here: Latest Version: GNU Aspell 0.50.5 (Released Feb, 2004)

I've been reading the UNIX  Installation instructions
(http://aspell.net/man-html/2_Getting.html#SECTION00350000000000000000
and this C++ static variables business beats me. I'm sorry. Can anybody help? 

Marc

Average of ratings: -
In reply to Ludo (Marc Alier)

Re: The early Patch to add spell checking to the HTML Editor

by Janne Mikkonen -
Thanks for workin' on this Ludo big grin.

Do you intend to get it ready for release 1.4 ?

I'm not so sure about the changes made to use_html_editor function in weblib.php. If were going to change it, we'll need to make sure that its backward compatible and it also would be better if it is more flexible so we could make different kind of configurations possible to load through that function (fonts, sizes, custom buttons etc).

Any thougths?

- Janne -
In reply to Janne Mikkonen

Re: The early Patch to add spell checking to the HTML Editor

by Janne Mikkonen -
Argh! My test servers aspell is quite old so I'm not sure does it work???

Add $CFG->aspellpath = '/path/to/aspell' to config.php

I've made some changes:
------------------------------------------------
copy speller folder to /moodle/lib/

weblib.php
function use_html_editor($name="",$courseid=0) {

/// Sets up the HTML editor on textareas in the current page.
/// If a field name is provided, then it will only be
/// applied to that field - otherwise it will be used
/// on every textarea in the page.
///
/// In most cases no arguments need to be supplied

// Modification by Ludo ( Marc Alier to provide Spell Checking to the
// html editor. August 2004 malier@lsi.upc.es
/// START LUDO
    global $CFG;
    if(!empty($CFG->aspellpath)) {
        echo "<script src=\"".$CFG->wwwroot."/lib/speller/spellChecker.js\"></script>";
    }

/// END LUDO

    echo "<script language=\"javascript\" type=\"text/javascript\" defer=\"1\">\n";
    if (empty($name)) {
        echo "HTMLArea.replaceAll();\n";
    } else {
        if(!empty($CFG->aspellpath)) {
        //START LUDO
            echo "function clickHandler(editor, buttonId) {";
            echo "editor._textArea.value = editor.getHTML();";
            echo "var speller = new spellChecker( editor._textArea );";
            echo "speller.popUpUrl ='$CFG->wwwroot/lib/speller/spellchecker.html';";
            echo "speller.spellCheckScript = '$CFG->wwwroot/lib/speller/server-scripts/spellchecker.php?id=$courseid';";
            echo "speller._moogle_edit=1;";
            echo "speller._editor=editor;";
            echo "speller.openChecker();";
            //echo "    editor.setHTML(editor._textArea.value);";
            echo "}\n"  ;
            echo "var config = new HTMLArea.Config();\n";
            echo "config.registerButton(\"spell-check\",  \"spell-check\", \"".$CFG->wwwroot."/lib/speller/spell.gif\", false, clickHandler);";
            echo "config.toolbar.push([\"spell-check\"]);\n";
            echo "HTMLArea.replace('$name', config);\n";
        // FI LUDO */
        } else {
            echo "HTMLArea.replace('$name');\n";
        }
    }
    echo "</script>\n";
}


changes.txt can be found in speller.zip and we really should think this use_html_editor -function through smile

- Janne -
In reply to Janne Mikkonen

Re: The early Patch to add spell checking to the HTML Editor

by W Page -
Hi Janne,

If you use linux/unix, how were you able to get this C++ stuff going.  I cannot figure it out.  I  do have SSH access.  Is there something I could read that would help me in installing Aspell on a Linux/Unix server??

WP1
In reply to W Page

Re: The early Patch to add spell checking to the HTML Editor

by Janne Mikkonen -
Its already installed (Fedora Core 1 Dist) big grin .

First you'd check if its already present
$ whereis aspell
or on rpm's are used:
$ rpm -qa | grep aspell

If you get path infos (whereis) or list installed rpm's, you already have it. If not, you have to install it.

Basically all the source installations follows the same pattern:
  1. Extract source code into a directory (eg /usr/local/src/<package>).
  2. Run configure script in the source folder (./configure)
  3. Build binaries (make)
  4. Install software (make install).
So here's what you should do:
  1. Extract aspell source to a directory:
    $ cd /usr/local/src
    $ tar -xzvf <package>.tar.gz
  2. Run configure script:
    $cd <package>
    $ ./configure
  3. Build binaries from source:
    $make
  4. Install the software (if make goes through, it'll give an error message if something goes wrong):
    $ make install
So basically thats it smile

Do you have a Linux/unix box where you can train building from source?

- Janne -