Plugin API: Expose "Add to Dictionary" functionality

I would like for there to be a programmatic way in the plugin API to trigger the “Add to Dictionary” functionality.

Use case or problem

I am developing a plugin that allows maintaining a vault “Glossary” of terms and their definitions. As part of the functionality for adding a word to the glossary, I would also like to add it to the dictionary.

Proposed solution

I know that Obsidian uses Electron’s spellcheck and dictionary functionality under the hood, but I’m looking for something higher level that performs the programmatic equivalent of a user selecting “Add to Dictionary” from the editor context menu. Something simple like editor.addToDictionary(word);. I can imagine that this API could be invoked just before (or after) Obsidian invokes Electron’s built-in functionality.

Current workaround (optional)

I’ve been working on a way to directly manipulate the underlying Custom Dictionary.txt files using Node, but challenges are arising regarding the checksum synchronization with the OS dictionary, as well as the inability to refresh Obsidian/Electron’s internal memory of words for spell checking (so the red underline does not go away).

Conclusion

I’m mostly building this for myself, as I use the same Obsidian vault on four different machines and work in a domain with a lot of non-standard terminology. It would be nice to not only use this “Glossary” to sync terms between machines, but also to define and reference them in my notes.

5 Likes

I would also find this useful. I made a plugin which fixes misspellings with keyboard shortcuts and autocorrect, and it accesses the dictionary to make sure it doesn’t correct words the user added to the dictionary. But since there’s no standard way to do it, I have to do it in an inelegant way which the ObsidianReviewBot catches as a required fix (ctrl+F “Obsidian’s configuration folder” here). I would also like to add a shortcut for adding a word to the dictionary, and automatically add to dictionary a capitlaized version of each lowercase word that is added, but I don’t want to do it in a non-standard way.

Making spellcheck dictionary an editable note is also a valid alternative.

1 Like

I have made a plugin for synonyms (swedish and english) that also is able to add your own custom synonyms.
Take a look if there is anything in it you can use for your plugin.