Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed nested/spanned node issues #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lkspencer
Copy link

Fixes a number of issues with nested/spanned nodes and simplifies the regular expressions.

Fixes a number of issues with nested/spanned nodes and simplifies the regular expressions.
@lkspencer
Copy link
Author

If you go to the CKEditor demo and paste the following HTML into the source, previously it would not find and replace all of the misspelled words. I've used several situations of spanned nodes and partial words and particularly teste followed by stem cell would previously get concatinated in the old code to testestem cell which has teste in there twice making it more difficult to properly find the right instance and correct it. This update takes care of every one of these situations.

<p>this is a test</p>

<p>I need to <strike>k</strike><em><strike>n<strong>o</strong></strike>o</em>w</p>

<p>if it will woork</p>

<p>testi knoow <strike>wo<u>o</u><em>r</em><strong>k</strong></strike></p>

<p>testily</p>

<p>teste</p>

<p>stem cell</p>

@@ -484,7 +501,9 @@
};

TextParser.prototype.replaceWordInText = function(oldWord, newWord, text) {
var regex = new RegExp('(^|[^' + letterChars + '])(' + RegExp.escape(oldWord) + ')(?=[^' + letterChars + ']|$)', 'g');
//MODIFIED BY Kirk Spencer
var regex = new RegExp('\\b(' + RegExp.escape(oldWord) + ')\\b', 'g');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\b is suitable for Latin characters but it doesn't work correctly with all Unicode characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants