public static string CleanupHtml(string html, string baseUrl, bool preserveImages, bool strip, bool preserveTables)
        {
            // sterilize the HTML
            html = UnsafeHtmlFragmentHelper.SterilizeHtml(html, UnsafeHtmlFragmentHelper.Flag.AllFlags ^ UnsafeHtmlFragmentHelper.Flag.RemoveStyles);

            html = StripNamespacedTags(html);

            // get the text into a DOM to ensure tags are balanced
            IHTMLDocument2 document = HTMLDocumentHelper.StringToHTMLDoc(html, null, false);

            if (document.body == null)
            {
                return(string.Empty);
            }

            // thin it
            if (preserveTables)
            {
                html = LightWeightHTMLThinner2.Thin(document.body.innerHTML, preserveImages, strip, LightWeightHTMLThinner2.PreserveTables);
            }
            else
            {
                html = LightWeightHTMLThinner2.Thin(document.body.innerHTML, preserveImages, strip);
            }
            html = LightWeightHTMLUrlToAbsolute.ConvertToAbsolute(html, baseUrl, false, true, true);

            // balance it
            string balancedHtml = HTMLBalancer.Balance(html);

            // return
            return(balancedHtml);
        }
 public static string PreserveFormatting(string html, string baseUrl)
 {
     UnsafeHtmlFragmentHelper.Flag flags = UnsafeHtmlFragmentHelper.Flag.RemoveDocumentTags |
                                           UnsafeHtmlFragmentHelper.Flag.RemoveScriptTags |
                                           UnsafeHtmlFragmentHelper.Flag.RemoveScriptAttributes |
                                           UnsafeHtmlFragmentHelper.Flag.RemoveMarkupDirectives |
                                           UnsafeHtmlFragmentHelper.Flag.RemoveComments;
     html = UnsafeHtmlFragmentHelper.SterilizeHtml(html, flags);
     html = LightWeightHTMLUrlToAbsolute.ConvertToAbsolute(html, baseUrl, false, true, true);
     return(html);
 }
 public static string RemoveScripts(string html)
 {
     return(UnsafeHtmlFragmentHelper.SterilizeHtml(html, UnsafeHtmlFragmentHelper.Flag.RemoveDocumentTags | UnsafeHtmlFragmentHelper.Flag.RemoveScriptTags | UnsafeHtmlFragmentHelper.Flag.RemoveScriptAttributes));
 }