Skip to content

Commit

Permalink
AI Assistant: Write Brief should not flag words like '2nd' and '100th…
Browse files Browse the repository at this point in the history
…' as spelling errors. (#39880)

* AI Assistant: Write Brief should not flag words like '2nd' and '100th' as spelling errors.

* changelog

* Typescript expects isNaN to be passed a number
  • Loading branch information
mwatson authored Oct 24, 2024
1 parent 0ac7dd1 commit 7b79cd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

AI Assistant: Write Brief should not flag words like '2nd' and '100th' as spelling errors.
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ export default function spellingMistakes( text: string ): Array< HighlightedText
// \p{M} matches any Unicode mark (combining characters)
// The regex has three main parts:
// 1. [@#+$/]{0,1} - Optionally matches a single special character at the start
// 2. [\p{L}\p{M}'-]+ - Matches one or more letters, marks, apostrophes, or hyphens
// 3. (?:\/[\p{L}\p{M}'-]+)* - Optionally matches additional parts separated by slashes
const wordRegex = new RegExp( /[@#+$/]{0,1}[\p{L}\p{M}'-]+(?:\/[\p{L}\p{M}'-]+)*/gu );
// 2. [\p{L}\p{M}\p{N}'-]+ - Matches one or more letters, marks, numbers, apostrophes, or hyphens
// 3. (?:\/[\p{L}\p{M}\p{N}'-]+)* - Optionally matches additional parts separated by slashes
const wordRegex = new RegExp( /[@#+$/]{0,1}[\p{L}\p{M}\p{N}'-]+(?:\/[\p{L}\p{M}\p{N}'-]+)*/gu );
const matches = Array.from( text.matchAll( wordRegex ) );

matches.forEach( match => {
Expand All @@ -199,6 +199,11 @@ export default function spellingMistakes( text: string ): Array< HighlightedText
return;
}

// Skip anything that is a valid number
if ( ! isNaN( Number( word ) ) ) {
return;
}

// Split words by hyphens and slashes
const subWords = word.split( /[-/]/ );

Expand Down

0 comments on commit 7b79cd0

Please sign in to comment.