-
Notifications
You must be signed in to change notification settings - Fork 146
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
Replace with multiple capture groups fails to recognise how to restore HTML #72
Comments
How about using a findAndReplaceDOMText(document.querySelector("#test"), {
find: /(hello)(world)/,
replace: function replace(portion, match) {
var txt = portion.text;
if (portion.text === match[1])
txt += '!!!';
return document.createTextNode(txt);
}
}); |
This won't work when text is spread over multiple HTML elements/findAndReplaceDOMText's portions (and it is in my case, I've simplified it in the fiddle) |
Could you post a fiddle with your unsimplified use case? |
https://jsfiddle.net/q1nnnzk9/ - this should be enough for a sample |
Change the if statement to if (portion.indexInMatch + portion.text.length === match[1].length) |
the if example above is not working if you don`t start a new node at an capture group
but it would be cool to have an internal |
i suggest that we enhance the Wrap syntax with this
results in: and if you dont want add new wraps simply use $1{$2}{$3}$4 |
Example: https://jsfiddle.net/zzby5zb6/1/
Actually, this isn't technically incorrect, as the
replace
function has no way of knowing if the intention was to put the!!!
inside of thespan
element or outside of it.As far as I understand, this is limited by the current design. I understand your desire to stay true to the original regexp/replace syntax, but to avoid such scenarios, maybe it would make sense to consider using capture group delimiters? Being able to express something like
{$1!!!}{$2}
would solve the issue.The text was updated successfully, but these errors were encountered: