platers / obsidian-linter

An Obsidian plugin that formats and styles your notes with a focus on configurability and extensibility.
https://platers.github.io/obsidian-linter/
MIT License
1.11k stars 76 forks source link

FR: Add Support for Custom Auto-Correct Misspellings #866

Open Skroderider opened 10 months ago

Skroderider commented 10 months ago

Is Your Feature Request Related to a Problem? Please Describe.

I would like to add in custom auto-correct misspellings for things that might be specific to me (i.e. misspelling PowerShell as Powershell) but might be too frivolous to request adding to the main auto-correct map located here Auto-correct map.ts

Describe the Solution You'd Like

A new input box similar to "Ignore Words" in the Content tab which allows me to enter in custom autocorrect words. I'd be happy with any format the devs choose, but I think using an array format like below makes most sense.

['Powershell'],['PowerShell'], 
['diahorrea', 'diarrhea']

Please include an example where applicable:

Current example

You'll need: [A supported version of Windows](https://docs.chocolatey.org/en-us/chocolatey-components-dependencies-and-support-lifecycle#supported-windows-versions)
Powershell 2.0 or higher
    Powershell 3.0 

Corrected example

You'll need: [A supported version of Windows](https://docs.chocolatey.org/en-us/chocolatey-components-dependencies-and-support-lifecycle#supported-windows-versions)
PowerShell 2.0 or higher
    PowerShell 3.0 

Describe Alternatives You've Considered

I tried using the plugin Completr, but found it to be excessive for my needs.

Additional Context

I have included a mockup of the UI element for your consideration.

image
pjkaufman commented 10 months ago

Hey @Skroderider , thanks for the suggestion. Is there a particular reason why Custom Regex Replacement would not work for what you are trying to do here?

It would be much cleaner and be less prone to input issues that would come along with having to input a JS map/array type value into a text box.

Skroderider commented 9 months ago

Honestly had never occurred to me to use regex to fix spelling mistakes! I can do that, no problems

Gewerd-Strauss commented 7 months ago

I think however that this should be reconsidered, for several reasons:

  1. Regex is comparatively more complicated, particularly to people who don't or rarely use it. It's not exactly a common thing once you step outside programming/coding.
  2. Simplicity. Editing a textfile which is read into the map allows a user to keep simple replacements which are much easier to deal with without regex.

However, as I am not fluent in javascript-regex (JS is not my focus at all and time is all too short right now), I could not figure out how to do this myself to open up for PR. Instead, I have a small script which modifies the relevant line in the compiled js file installed:

}, We = class extends Wi { buildOption() { return new Vn(this.configKey, this.nameKey, this.descriptionKey, this.defaultValue) } }, cs = class extends Wi { buildOption() { return new is(this.configKey, this.nameKey, this.descriptionKey, this.defaultValue) } }; var sl = new Map([["magno", "mango"], ["qpcr", "qPCR"], ["pca", "PCA"], ["arbeit", "arbeit"], ["judsa", "Judas"], ["jdusa", "Judas"], ["madnatory", "mandatory"], ["uniformaly", "uniformly"], 

where variable sl contains all custom word replacements. It prepends custom definitions to the beginning of the array, thus allowing me to sidestep the issue entirely. The Hot Reload plugin then deals with reloading the plugin on the fly due to its filechange.

pjkaufman commented 7 months ago

Hey @Gewerd-Strauss , it sounds like we may be talking past each other or I have poorly explained/documented how custom replace works. Custom replace is designed for regex usage. However regex is not necessary. If you just use values as is (i.e. type in the find text as is and the replace text as is) then no regex knowledge is necessary.

It may make sense to add a checkbox for regular find and replace to make that the type for custome replace, but it will be case sensitive in that case.

Edit: Is this what you are asking for or am I missing something? I ask because autocorrect is a complex system that will get unrully if it is allowed to have custom input. If you have an idea on how to avoid making the settings screen clunky while adding custom replace values, I can see this being possible.

Gewerd-Strauss commented 7 months ago

I will quickly answer this in part because I am unfortunately extremely short on time and have no clue if I can answer over the coming week.

If you have an idea on how to avoid making the settings screen clunky while adding custom replace values, I can see this being possible.

One could simply ask for a user to supply a simple file containing needle/replace pairs. THat file could be part of the vault, or be located elsewhere on the computer. I have no experience writing this, but the Zotero integration has a file dialogue in its options (clicking on the folder-icon): grafik

SUch a means (or heck, even a super simple input line to give a path to a txt-file to be read in at plugin startup) could be used to load pairs from a custom user-sided file - which then shouldn't be purged upon plugin changes/reinstalls/deinstalls/whatever.


Edit 26.11.2023 15:10

To elaborate, I suggest a file as input, over the current implementation. Or maybe these kinds of data gets written to a simple file from the UI, but the file should follow a simple format so that external modification/generation of possible.

Obsidian already behaves moreso like a code editor, heck you could argue it to be somewhat closer to a typical IDE than a simple word processor. With that in mind, and considering all the other under-the-hood stuff obsidian users are happy to do via files and configurations, this should be a simple complementary solution to make using this much more efficient for those who need it.

pjkaufman commented 7 months ago

If I were to use a file format, I would much prefer either YAML as the key value pairs or a table that has only two columns and has all | values present since that would make the most sense to me personally. I would really hate having to deal with JSON in a markdown file. So if I were to add a file to reference it would need likely use a table. That will be very hard to explain in the description so it would need to link out to the documentation website to handle the explanation of the expected file format.

But beyond that, if there is nothing wrong with that, I would be fine with proceeding with this.

Gewerd-Strauss commented 7 months ago

Sounds good to me.

pjkaufman commented 1 week ago

I am currently working on this feature. But it may take me a minute to get this ready and present. I want it to be able to have a popup that lets the user know the exact values and their replacements that were found in a file specified as well as a count of how many word replacements were found in the file. So far I have started the process of just getting the setting to show up in the UI even though it does not fit the normal kind of rule setting.