@Mark, included your third example to create this, for reference:
public static string CleanUpRteOutput(this string s)
{
if (s != null)
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(s);
RemoveTag(doc, "script");
RemoveTag(doc, "link");
RemoveTag(doc, "style");
RemoveTag(doc, "meta");
RemoveTag(doc, "comment");
...
and removeTag function:
static void RemoveTag(HtmlAgilityPack.HtmlDocument doc, string tag)
{
foreach (var n in doc.DocumentNode.SelectNodes("//" + tag) ?? new HtmlAgilityPack.HtmlNodeCollection(doc.DocumentNode))
n.Remove();
}
source
share