Exemple #1
0
 public static string StandardizationHTML(string html, bool isClearCommentary, bool isClearScript, bool isClearStyle, bool isReplenishHtmlTag)
 {
     if (html.Trim() == "")
     {
         return "";
     }
     if (isReplenishHtmlTag)
     {
         string str = html.ToUpper();
         if (!str.StartsWith("<HTML"))
         {
             int index = str.IndexOf("<HTML");
             if (index > 0)
             {
                 html = html.Substring(index, str.Length - index);
             }
             else
             {
                 html = "<HTML>" + html;
             }
         }
         str = html.ToUpper();
         if (!str.EndsWith("</HTML>"))
         {
             int length = str.LastIndexOf("</HTML>");
             if (length > 0)
             {
                 html = html.Substring(0, length) + "</HTML>";
             }
             else
             {
                 html = html + "</HTML>";
             }
         }
     }
     Shove.HTML.SgmlReader.SgmlReader reader = new Shove.HTML.SgmlReader.SgmlReader();
     reader.DocType = "HTML";
     reader.InputStream = new StringReader(html);
     reader.CaseFolding = CaseFolding.ToUpper;
     reader.WhitespaceHandling = WhitespaceHandling.None;
     StringWriter w = new StringWriter();
     XmlTextWriter writer2 = new XmlTextWriter(w);
     writer2.Formatting = Formatting.Indented;
     string str2 = "";
     try
     {
         while (reader.Read())
         {
             if (reader.NodeType != XmlNodeType.Whitespace)
             {
                 writer2.WriteNode(reader, true);
             }
         }
     }
     catch
     {
     }
     str2 = w.ToString();
     if (isClearCommentary && (str2 != ""))
     {
         str2 = ClearCommentary(str2);
     }
     if (isClearScript && (str2 != ""))
     {
         str2 = ClearScript(str2);
     }
     if (isClearStyle && (str2 != ""))
     {
         str2 = ClearStyle(str2);
     }
     if ((!isClearCommentary && !isClearScript) && !isClearStyle)
     {
         return str2;
     }
     return StandardizationHTML(str2, false, false, false, isReplenishHtmlTag);
 }
Exemple #2
0
        public static string StandardizationHTML(string html, bool isClearCommentary, bool isClearScript, bool isClearStyle, bool isReplenishHtmlTag)
        {
            if (html.Trim() == "")
            {
                return("");
            }
            if (isReplenishHtmlTag)
            {
                string str = html.ToUpper();
                if (!str.StartsWith("<HTML"))
                {
                    int index = str.IndexOf("<HTML");
                    if (index > 0)
                    {
                        html = html.Substring(index, str.Length - index);
                    }
                    else
                    {
                        html = "<HTML>" + html;
                    }
                }
                str = html.ToUpper();
                if (!str.EndsWith("</HTML>"))
                {
                    int length = str.LastIndexOf("</HTML>");
                    if (length > 0)
                    {
                        html = html.Substring(0, length) + "</HTML>";
                    }
                    else
                    {
                        html = html + "</HTML>";
                    }
                }
            }
            Shove.HTML.SgmlReader.SgmlReader reader = new Shove.HTML.SgmlReader.SgmlReader();
            reader.DocType            = "HTML";
            reader.InputStream        = new StringReader(html);
            reader.CaseFolding        = CaseFolding.ToUpper;
            reader.WhitespaceHandling = WhitespaceHandling.None;
            StringWriter  w       = new StringWriter();
            XmlTextWriter writer2 = new XmlTextWriter(w);

            writer2.Formatting = Formatting.Indented;
            string str2 = "";

            try
            {
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Whitespace)
                    {
                        writer2.WriteNode(reader, true);
                    }
                }
            }
            catch
            {
            }
            str2 = w.ToString();
            if (isClearCommentary && (str2 != ""))
            {
                str2 = ClearCommentary(str2);
            }
            if (isClearScript && (str2 != ""))
            {
                str2 = ClearScript(str2);
            }
            if (isClearStyle && (str2 != ""))
            {
                str2 = ClearStyle(str2);
            }
            if ((!isClearCommentary && !isClearScript) && !isClearStyle)
            {
                return(str2);
            }
            return(StandardizationHTML(str2, false, false, false, isReplenishHtmlTag));
        }