How do you highlight (or give any special markup) special characters like ‘’“”‛‟′″˝
? Thanks. Using a find and replace .innerHTML.replace()
doesn't work as it ruins the event handlers and the DOM.
I've tried the following, but that just ends up with the span
's in plain text instead of code.
function highlightText(node, find, rep){
if(node){
node= node.firstChild;
while(node!= null){
if(node.nodeType== 3){
node.data= node.data.replace(find, rep);
}
else highlightText(node, find, rep);
node= node.nextSibling;
}
}
return true;
}
highlightText(document.body,/‘/g, "<span style='background: red; color: white;'>‘</span>")
highlightText(document.body,/’/g, "<span style='background: red; color: white;'>’</span>")
highlightText(document.body,/“/g, "<span style='background: red; color: white;'>“</span>")
highlightText(document.body,/”/g, "<span style='background: red; color: white;'>”</span>")
highlightText(document.body,/‛/g, "<span style='background: red; color: white;'>‛</span>")
highlightText(document.body,/‟/g, "<span style='background: red; color: white;'>‟</span>")
highlightText(document.body,/′/g, "<span style='background: red; color: white;'>′</span>")
highlightText(document.body,/″/g, "<span style='background: red; color: white;'>″</span>")
highlightText(document.body,/˝/g, "<span style='background: red; color: white;'>˝</span>")