====== Jupyter UK Spellchecker ====== The information summarised here is taken from the articles referenced below and configured for uk spelling. * [[https://stackoverflow.com/questions/39324039/highlight-typos-in-the-jupyter-notebook-markdown]] * [[https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions/spellchecker]] ===== Installation ===== The following three lines of code needs to be run to install the basic tools for Jupyter Notebook. Before running this shut down all running notebooks or active Jupyter sessions. pip install jupyter_contrib_nbextensions jupyter contrib nbextension install --user jupyter nbextension enable spellchecker/main The commands can be run in any Python enabled environment. Run them one at a time and look for error messages. {{:help:developer_tools:spellchecker_jupyter.png?nolink|}} The spellchecker button should now appear in the notebooks, make sure it is checked on and misspelled words should now be highlighted in markup section when in edit mode in the notebooks. ===== Configure for UK spelling ===== Setting the dictionary to UK Enlish requires editing the spellchecker configuration file. Again ensure that no notebooks are running and shut down all jupyter active sessions too before editing the configuration file. The hints for editing this file can be found in the spellcheker git page((https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions/spellchecker)). The challenge is finding this file as it gets installed in different places by various distributions. On windows pc's with Anaconda it should be in the following location: C:\ProgramData\Anaconda3\Lib\site-packages\jupyter_contrib_nbextensions\nbextensions\spellchecker In the folder there is a python file called download_new_dict.py. from __future__ import print_function import base64 import os.path from jupyter_core.paths import jupyter_data_dir from notebook.services.config import ConfigManager try: from urllib.request import urlopen # Py3 except ImportError: from urllib import urlopen # Py2 remote_base_url = ( 'https://chromium.googlesource.com/' + 'chromium/deps/hunspell_dictionaries/+/master' ) local_base_url = os.path.join( jupyter_data_dir(), 'nbextensions', 'spellchecker', 'typo', 'dictionaries') lang_code = 'en_GB' if not os.path.exists(local_base_url): print('creating directory {!r}'.format(local_base_url)) os.makedirs(os.path.realpath(local_base_url)) cm = ConfigManager() for ext in ('dic', 'aff'): dict_fname = lang_code + '.' + ext remote_path = remote_base_url + '/' + dict_fname + '?format=TEXT' local_path = os.path.join(local_base_url, dict_fname) print('saving {!r}\n to {!r}'.format(remote_path, local_path)) with open(local_path, 'wb') as loc_file: base64.decode(urlopen(remote_path), loc_file) rel_path = './typo/dictionaries/' + dict_fname cm.update('notebook', {'spellchecker': {ext + '_url': rel_path}}) cm.update('notebook', {'spellchecker': {'lang_code': lang_code}}) Around the middle of the file edit the language code to en_GB, save the file and run the script. This script download the UK dictionaries locally and sets the path variables to load the files on starting the notebook. Starting the notebook in debug mode should show the proper loading of the new dictionaries, i.e. "jupyter noebook --debug" [D 13:30:15.266 NotebookApp] 200 GET /nbextensions/spellchecker/main.css?v=20181105133001 (127.0.0.1) 13.03ms [D 13:30:15.281 NotebookApp] Path spellchecker\typo\dictionaries\en_GB.aff served from C:\Users\winuser\AppData\Roaming\jupyter\nbextensions\spellchecker\typo\dictionaries\en_GB.aff [D 13:30:15.283 NotebookApp] 200 GET /nbextensions/spellchecker/typo/dictionaries/en_GB.aff?v=20181105133001 (127.0.0.1) 3.01ms [D 13:30:15.292 NotebookApp] Path spellchecker\typo\dictionaries\en_GB.dic served from C:\Users\winuser\AppData\Roaming\jupyter\nbextensions\spellchecker\typo\dictionaries\en_GB.dic [D 13:30:15.299 NotebookApp] Initializing websocket connection /api/kernels/da53f4c0-524a-4fdd-b28c-785112af6109/channels