badsyntax / jquery-spellchecker

[not maintained] A lightweight jQuery plugin that can check the spelling of text within a form field or DOM tree.
http://jquery-spellchecker.badsyntax.co
MIT License
257 stars 113 forks source link

Spelling error does not trigger with the DOM has only ONE word #56

Open shriniv78 opened 11 years ago

shriniv78 commented 11 years ago

In the demo environment url below, if you erase everything and just type one bad spelling "eg: denounncing", the error style/event bind does not happen. Same issue in my local. I am using nhunspell, and newton for my backend.

Also, its the same issue if the first word or the last word contains has bad spelling.

http://jquery-spellchecker.badsyntax.co/ckeditor.html

motan commented 11 years ago

I've fixed it in my project.

we need to update code in HtmlParser.prototype.highlightWords method.

find

var regExp = ''; regExp += '([^' + letterChars + '])'; regExp += '(' + incorrectWords.join('|') + ')'; regExp += '(?=[^' + letterChars + '])';

and replace it with

var regExp = ''; regExp += '([^' + letterChars + ']?)'; regExp += '(' + incorrectWords.join('|') + ')'; regExp += '(?=[^' + letterChars + ']?)';

(in 2 and 4 rows "?"-sign added before closing bracket)

bryandevvv commented 10 years ago

The regex fix listed by motan does not work for me, because it highlights misspelled words in other words. For instance if "wor" were highlighted as misspelled, any "wor" in "word" would also be highlighted.
Any regex masters out there? The library as is does not highlight the first word, or words directly after a newline or html tag for me.

tangruixing commented 10 years ago

i replace it with

var regExp = ''; regExp += '(^|[^' + letterChars + '])'; regExp += '(' + incorrectWords.join('|') + ')'; regExp += '(?=[^' + letterChars + ']|$)';

ss81 commented 9 years ago

The patch provided by tangruixing works well for me.

bogdan-dinu-me commented 9 years ago

the last patch doesn't match last words in paragraphs that don't have a punctuation sign.

I propose this variant which matches both first and last words:

var regExp = ''; regExp += '(^|[^' + letterChars + ']?)'; regExp += '(' + incorrectWords.join('|') + ')'; regExp += '(?=[^' + letterChars + ']?)';