Forum Discussion
AlexeyKolosov
14 years agoStaff
Hi 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.
Related Content
- 8 years ago
- 12 years ago
- 8 years ago
- 8 years ago
- 12 months ago
Recent Discussions
- 3 days ago
- 3 days ago
- 7 days ago