replace whitespace characters in text also #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
per https://adactio.com/journal/11632
I'll take a stab.
What I'm seeing is the text that gets passed in the #hash has a non-breaking space character in between the last two words, which matches the markup.
However, in
getElementsByText
the passedtext
is being compared to the.innerText
or.textContent
of the node like so:.replace(/\s+/g, ' ')
will find any whitespace character, crucially including non-breaking space characters, and replace them all with a regular space.However
text
in.indexOf(text)
will still have the non-breaking space. So the strings will be technically different and you won't find a match.Run the same
.replace(/\s+/g, ' ')
on both the element's innerText and the passedtext
and it appears to work.(You might also be able to lose the replace in both places, but I imagine it's there for a reason.)