Skip to content

jperezlatimes/ckenchanter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ckenchanter

Extends the PyEnchant library to parse requests from CKEditor's SCAYT spellchecker plugin and return suggested corrections using standard language dictionaries and custom personal word lists. Use it to run your own lightweight spellchecking server.

Installing

Install to your virtualenv or globally using pip.

pip install ckenchanter

Client side configuration

To begin you'll need to add the following lines to your CKEditor config.js file. Update the values to reflect your app settings.

config.scayt_autoStartup = true;
config.scayt_servicePath = '/spellcheck/';
config.scayt_serviceHost = 'localhost';
config.scayt_servicePort = '8005';
config.scayt_serviceProtocol = 'http';

This can also be done when CKEditor is initialized in your app through the global CKEDITOR object.

The config.scayt_servicePath endpoint should submit the request data to a CKEnchanter object and return it's response. Here is an example Flask route:

Usage on server

from ckenchanter import CKEnchanter

@views.route('/spellcheck/', methods=['POST'])
def spellcheck():
    """
    Sends a line of text to the ckenchanter module
    """
    cke = CKEnchanter()
    response = cke.parse_ckeditor_request(request.data)
    return jsonify(response)

CKEnchanter accepts all arguments supported by PyEnchant's SpellChecker class. It has an additional named arg wl_path that accepts the absolute path of a custom word list (.txt file) for CKEnchanter to use in addition to the default dictionary.

import os
from ckenchanter import CKEnchanter

@views.route('/spellcheck/', methods=['POST'])
def spellcheck():
    """
    Sends a line of text to the ckenchanter module
    """
    file_dir = os.path.dirname(__file__)
    word_list_path = os.path.join(file_dir, "dicts/mywords.txt")

    cke = CKEnchanter(wl_path=word_list_path)
    response = cke.parse_ckeditor_request(request.data)
    return jsonify(response)

That's it! CKEnchanter will extract the text from CKEditor's request string and run it through PyEnchant, returning a list of suggestions formatted for SCAYT. Enjoy!

About

A PyEnchant extension for CKEditor's SCAYT plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published