mir3z / texthighlighter

-- NO LONGER MAINTAINED -- TextHighlighter allows you to highlight text on web pages.
http://mir3z.github.com/texthighlighter/
MIT License
230 stars 101 forks source link

Highlights fail to merge when separated by a space #6

Open findzen opened 10 years ago

findzen commented 10 years ago

Steps to reproduce: 1) Given string "Lorem ipsum", highlight "Lorem" 2) Highlight "ipsum" using same color 3) Highlight "Lorem ipsum"

The space is not highlighted and therefore the highlights are not merged. Removing the regex check seems to solve this: https://github.com/mir3z/jquery.texthighlighter/blob/master/src/jquery.textHighlighter.js#L193

Was there another reason for this test? Given the node type has already been verified as text, wouldn't node.nodeValue always be a string?

JoobyPM commented 10 years ago

This bad idea. As result you will have a lot of "blank" spans (with any of those characters \f\n\r\t\v\u00A0\u2028\u2029) - it will be bad for html structure. I had problem with "a new line character", when try to highlight the table. Better modify condition: /\S/.test(node.nodeValue) || node.nodeValue.length ==1