protected void CheckSpaces(Html.TextNode doc)
 {
     int zero = 0, other = 0, broken = 0, brokenother = 0;
     foreach (var ws in doc.TopDownNodes.OfType<Html.Token>().Where(t => t.IsWhitespace)) {
         if ((ws.Value == string.Empty) != (ws.Length == 0)) broken++;
         if (ws.Value == string.Empty) zero++;
         else other++;
         if (ws.Length > 0 && ws.Value == string.Empty) {
             brokenother++;
         }
     }
     Debug.Message("CheckSpaces: zero: {0}, other: {1}, broken: {2}, brokenother: {3}", zero, other, broken, brokenother);
 }
Exemple #2
0
 public static string CleanHtml(string html, Html.HtmlWriterOptions options)
 {
     try
     {
         Html.HtmlReader r = new Html.HtmlReader(html);
         StringWriter sw = new StringWriter();
         Html.HtmlWriter w = new Html.HtmlWriter(sw, options);
         while (!r.EOF)
         {
             w.WriteNode(r, true);
         }
         w.Close();
         return sw.ToString();
     }
     catch (Exception e)
     {
         return e.Message;
     }
 }
 TreeNode GetNode(Html.Element e)
 {
     var node = new TreeNode();
     node.Text = string.Format("<span style='color:green'>line</span> {0}: {1}", e.StartTag.StartToken.Line, Server.HtmlEncode(e.StartTag.Text));
     node.Target = "_top";
     node.NavigateUrl = "javascript:PopupText(\"" + HttpUtility.HtmlEncode(e.Text).Replace(" ", "&#xB7;").Replace("\n", "&#xB6;<br/>").Replace("\t", "&nbsp; &raquo; &nbsp;").Replace("\"", "&quot;") + "\");";
     foreach (var child in e.Children.OfType<Html.Element>()) {
         node.ChildNodes.Add(GetNode(child));
     }
     return node;
 }