generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1132 from pjkaufman/custom-auto-corrections
Add Custom Auto-Correct Options
- Loading branch information
Showing
17 changed files
with
492 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import {parseCustomReplacements} from '../src/utils/strings'; | ||
import dedent from 'ts-dedent'; | ||
|
||
type parseCustomReplacementsTestCase = { | ||
name: string, | ||
text: string, | ||
expectedCustomReplacements: Map<string, string> | ||
}; | ||
|
||
const getTablesInTextTestCases: parseCustomReplacementsTestCase[] = [ | ||
{ | ||
name: 'parsing a file with a single table with two columns gets the correct amount of parsed out entries', | ||
text: dedent` | ||
Here is some text | ||
| column1 | column2 | | ||
| ------- | ------- | | ||
| replaceme | withme | | ||
| replace | with | | ||
`, | ||
expectedCustomReplacements: new Map<string, string>([['replaceme', 'withme'], ['replace', 'with']]), | ||
}, | ||
{ | ||
name: 'parsing a file with a single table with three columns gets no entries parsed out', | ||
text: dedent` | ||
Here is some text | ||
| column1 | column2 | column3 | | ||
| ------- | ------- | ---- | | ||
| replaceme | withme | me | | ||
| replace | with | me2 | | ||
`, | ||
expectedCustomReplacements: new Map<string, string>(), | ||
}, | ||
{ | ||
name: 'parsing a file with two tables with two columns gets the correct amount of parsed out entries', | ||
text: dedent` | ||
Here is some text | ||
| column1 | column2 | | ||
| ------- | ------- | | ||
| replaceme | withme | | ||
| replace | with | | ||
The following table also has some replacements | ||
| header1 | header2 | | ||
| ------- | ------- | | ||
| var | variablE | | ||
| hack | hacker | | ||
`, | ||
expectedCustomReplacements: new Map<string, string>([['replaceme', 'withme'], ['replace', 'with'], ['var', 'variablE'], ['hack', 'hacker']]), | ||
}, | ||
{ | ||
name: 'parsing a file with no tables gets no parsed out entries', | ||
text: dedent` | ||
Here is some text without any tables in it. | ||
`, | ||
expectedCustomReplacements: new Map<string, string>(), | ||
}, | ||
{ | ||
name: 'parsing a file with a single table with two columns gets no entries parsed out when each line is missing a pipe (i.e. |)', | ||
text: dedent` | ||
Here is some text | ||
| column1 | column2 | | ||
| ------- | ------- | | ||
| replaceme | withme | ||
replace | with | | ||
`, | ||
expectedCustomReplacements: new Map<string, string>(), | ||
}, | ||
]; | ||
|
||
describe('Get All Tables in Text', () => { | ||
for (const testCase of getTablesInTextTestCases) { | ||
it(testCase.name, () => { | ||
const customReplacements = parseCustomReplacements(testCase.text); | ||
|
||
expect(customReplacements).toEqual(testCase.expectedCustomReplacements); | ||
}); | ||
} | ||
}); |
32 changes: 32 additions & 0 deletions
32
docs/additional-info/rules/auto-correct-common-misspellings.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#### How to Use Custom Misspellings | ||
|
||
There is a default list of common misspellings that is used as the base for how this rule works. | ||
However, there may be instances where the user may want to add their own list of misspellings to handle. | ||
In those scenarios, they can add files to the list of files that have custom misspellings in them. | ||
|
||
##### Format | ||
|
||
A file that has custom misspellings in them can have any content in them. But the only content that will | ||
be parsed as custom misspellings should be found in a two column table. For example the following table | ||
will result in `th` being replaced with `the` and `tht` being replaced with `that`: | ||
|
||
``` markdown | ||
The following is a table with custom misspellings: | ||
| Replace | With | | ||
| ------- | ---- | | ||
| th | the | | ||
| tht | that | | ||
``` | ||
|
||
!!! Note | ||
The first two lines of the table are skipped (the header and separator) and all rows after that | ||
must start and end with a pipe (`|`). If any do not start or end with a pipe or they have more | ||
than 2 columns, then they will be skipped. | ||
|
||
##### Current Limitations | ||
|
||
|
||
- The list of custom replacements is only loaded when the plugin initially loads or when the file is added to the list of files that include custom misspellings | ||
* This means that making a change to a file that is already in the list of custom misspelling files will not work unless the Linter is reloaded or the file is removed and re-added to the list of custom misspelling files | ||
- There is no way to specify that a word is to always be capitalized | ||
- This is due to how the auto-correct rule was designed as it sets the first letter of the replacement word to the case of the first letter of the word being replaced |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.