I have a funtion that return to me a list of word (with the previous and next qord). I am able to locate the word in the text correctly using a RegEx and knowing the previous and next word (so I find only one time the word and not all of the same). I am actually using the replace function of Javascript to wrap it inside a SPAN :
var re = RegExp("(?:^\\W*|(" +
motBefore.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + ")\\W+)" +
motErreur.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "(?:\\W+(" +
motAfter.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + ")|\\W*$)", "g");
document.getElementById('edth_corps').innerHTML =
document.getElementById('edth_corps').innerText
.replace(re, motBefore + " " + '
'οncοntextmenu="rightClickMustWork(event, this);return false"> '
+ motErreur + '
' + " " + motAfter);But the fact is that because I am placed on the group of these three word, I have to give him back the word before and after.
The issue I got with this tech is that I loose all punctuation and the more important , if there is a font tag (or bold, italic, underline) I loose them.
I'd like to wrap around this word a span like it is the child of the current node where this word is without touching the previous and next word (they are suposed to be here so we have the right word and not another occurence of this word).
But I have no idea how to do it since I can only use old Javascript (IE compiler is set to compatibily mode for IE5, and this function is the only one I can't manage to rewrite for this version). I can't use library such a Jquery (I have seen a lot of solution with this plug in).
Could someone point me in the right direction ? Could an insertBefore work even if the Error Word has no parent around him but is only part of a sentence ?