From 8c05e7a9666907eb0b2ebf9a2a7c0635191277b3 Mon Sep 17 00:00:00 2001 From: Douglas Henri Date: Fri, 29 Nov 2024 19:21:46 -0300 Subject: [PATCH] Write Brief: Add alternative apostrophe char to spelling mistakes regex (#40395) * add alternative apostrophe char to regex * changelog * also strip apostrophes from the end --- .../changelog/fix-jetpack-ai-write-brief-apostrophe | 4 ++++ .../breve/features/spelling-mistakes/index.ts | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/fix-jetpack-ai-write-brief-apostrophe diff --git a/projects/plugins/jetpack/changelog/fix-jetpack-ai-write-brief-apostrophe b/projects/plugins/jetpack/changelog/fix-jetpack-ai-write-brief-apostrophe new file mode 100644 index 0000000000000..96b4337f20c6e --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-jetpack-ai-write-brief-apostrophe @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Write Brief: Add alternative apostroph char to spelling mistakes regex diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts index c0d0ce618c962..231c7e2709a6d 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts @@ -132,9 +132,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}\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 ); + // 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 => { @@ -155,8 +155,8 @@ export default function spellingMistakes( text: string ): Array< HighlightedText const subWords = word.split( /[-/]/ ); subWords.forEach( subWord => { - // remove single quotes from beginning/end - subWord = subWord.replace( /^'+|'+$/g, '' ); + // remove single quotes from beginning/end and apostrophes from the end + subWord = subWord.replace( /^'+|['’]+$/g, '' ); if ( ! spellChecker.correct( subWord ) ) { const subWordStartIndex = startIndex + word.indexOf( subWord );