Forum Discussion
AlexeyKolosov
Staff
15 years agoHi Ory,
Valid HTML stripping is quite a complex task, but you can try using something like this - should be enough for the majority of use cases:
function stripHtml(html)
{
var stripAllTags = new RegExp("(<style[^>]*?>(.*)(</style[^>]*?>|$))|(<script[^>]*?>(.*)(</script[^>]*?>|$))|(<[^<]*?>)", "g");
var text = html.replace(stripAllTags, " ");
// Expand common entities
var entityMapping = {};
entityMapping["""] = "\"";
entityMapping["'"] = "'";
entityMapping["<"] = "<";
entityMapping[">"] = ">";
entityMapping[" "] = " ";
entityMapping["&"] = "&";
for (var key in entityMapping)
{
text = text.replace(new RegExp(key, "g"), entityMapping[key]);
}
// Remove duplicated spaces
text = text.replace(new RegExp("(\\s){2,}", "g"), " ");
return text;
}
Does that mean that what Alexei suggested would not work?
This will make TestComplete display the message as formatted HTML, but will not strip HTML tags from the message.