Exemplo n.º 1
0
        public void reconstruct_formatting_elements()
        {
            // tests attributes and multi b
            string       h   = "<p><b class=one>One <i>Two <b>Three</p><p>Hello</p>";
            HtmlDocument doc = HtmlDocument.Parse(h);

            Assert.Equal(TextUtil.CompressWhitespace("<p><b class=\"one\">One <i>Two <b>Three</b></i></b></p>\n<p><b class=\"one\"><i><b>Hello</b></i></b></p>"),
                         TextUtil.CompressWhitespace(doc.Body.InnerHtml));
        }
Exemplo n.º 2
0
        public void reconstruct_formatting_elements_in_table()
        {
            // tests that tables get formatting markers -- the <b> applies outside the table and does not leak in,
            // and the <i> inside the table and does not leak out.
            string       h    = "<p><b>One</p> <table><tr><td><p><i>Three<p>Four</i></td></tr></table> <p>Five</p>";
            HtmlDocument doc  = HtmlDocument.Parse(h);
            string       want = "<p><b>One</b></p>\n" +
                                "<b> \n" +
                                " <table>\n" +
                                "  <tbody>\n" +
                                "   <tr>\n" +
                                "    <td><p><i>Three</i></p><p><i>Four</i></p></td>\n" +
                                "   </tr>\n" +
                                "  </tbody>\n" +
                                " </table> <p>Five</p></b>";

            Assert.Equal(TextUtil.CompressWhitespace(want), TextUtil.CompressWhitespace(doc.Body.InnerHtml));
        }
Exemplo n.º 3
0
        public void handles_unclosed_formatting_elements()
        {
            // whatwg: formatting elements get collected and applied, but excess elements are thrown away
            string h = "<!DOCTYPE html>\n" +
                       "<p><b class=x><b class=x><b><b class=x><b class=x><b>X\n" +
                       "<p>X\n" +
                       "<p><b><b class=x><b>X\n" +
                       "<p></b></b></b></b></b></b>X";
            HtmlDocument doc  = HtmlDocument.Parse(h);
            string       want = "<!DOCTYPE html>\n" +
                                "<html>\n" +
                                "<head></head>\n" +
                                "<body>\n" +
                                "<p><b class=\"x\"><b class=\"x\"><b><b class=\"x\"><b class=\"x\"><b>X </b></b></b></b></b></b></p>\n" +
                                "<p><b class=\"x\"><b><b class=\"x\"><b class=\"x\"><b>X </b></b></b></b></b></p>\n" +
                                "<p><b class=\"x\"><b><b class=\"x\"><b class=\"x\"><b><b><b class=\"x\"><b>X </b></b></b></b></b></b></b></b></p>\n" +
                                "<p>X</p>\n" +
                                "</body>\n" +
                                "</html>";

            Assert.Equal(TextUtil.CompressWhitespace(want), TextUtil.CompressWhitespace(doc.InnerHtml));
        }