I found the error. I was making a loop like:
$.each(RegularExp, function (name, value) {
if (RegularExp[name].test(self.nodeValue)) {
$(self).replaceWith(self.nodeValue.replace(RegularExp[name], Replacer[name]));
}
$output.find("span").each(function () {
if ($(this).hasClass("hex-color")) {
$(this).contrastColor("color", "background-color");
}
});
});
And the correct way to do it is:
var indice = 1,
texto = this.nodeValue;
$.each(RegularExp, function (name, value) {
if (RegularExp[name].test(self.nodeValue)) {
texto = texto.replace(RegularExp[name], Replacer[name])
}
if(indice == Object.keys(RegularExp).length){
$(self).replaceWith(texto);
}
$output.find("span").each(function () {
if ($(this).hasClass("hex-color")) {
$(this).contrastColor("color", "background-color");
}
});
indice++;
});