Exemple #1
0
 public void TestMoveToId()
 {
     using (var gumbo = new Gumbo(TestHtml))
     {
         var nav = gumbo.CreateNavigator();
         nav.MoveToId("tag123");
         Assert.AreEqual("p", nav.Name);
     }
 }
Exemple #2
0
        public void TestAttributes()
        {
            var testHtml = "<html><body class=\"gumbo\">привет!</body></html>";

            using (var gumbo = new Gumbo(testHtml))
            {
                var list = gumbo.Document.Root.Children.OfType <Element>().ToList();
                Assert.AreEqual("class", list[1].Attributes.First().Name);
                Assert.AreEqual("gumbo", list[1].Attributes.First().Value);
            }
        }
Exemple #3
0
 public void TestSelectSingleNodeAttribute()
 {
     using (var gumbo = new Gumbo(TestHtml))
     {
         var nav  = gumbo.CreateNavigator();
         var node = nav.SelectSingleNode("/html/body/@class");
         Assert.NotNull(node);
         Assert.AreEqual("gumbo", node.Value);
         Assert.AreEqual("class", node.Name);
         Assert.AreEqual("class", node.LocalName);
     }
 }
Exemple #4
0
 public void TestSelectSingleNodeForElement()
 {
     using (var gumbo = new Gumbo(TestHtml))
     {
         var nav  = gumbo.CreateNavigator();
         var node = nav.SelectSingleNode("/html/body/span");
         Assert.NotNull(node);
         Assert.AreEqual("Pillz here!", node.Value);
         Assert.AreEqual("span", node.Name);
         Assert.AreEqual("span", node.LocalName);
     }
 }
Exemple #5
0
        public void TestHeadBody()
        {
            var testHtml = "<html><body class=\"gumbo\">привет!</body></html>";

            using (var gumbo = new Gumbo(testHtml))
            {
                var list = gumbo.Document.Root.Children.OfType <Element>().ToList();
                Assert.AreEqual(GumboTag.GUMBO_TAG_HEAD, list[0].Tag);
                Assert.AreEqual(null, list[0].OriginalTag);
                Assert.AreEqual(GumboTag.GUMBO_TAG_BODY, list[1].Tag);
            }
        }
Exemple #6
0
        public void TestFirstAndLastTagsInEnum()
        {
            var testHtml = "<html><head><head><body><title></title><base></base><tt></tt><unknown123></unknown123></body></html>";

            using (var gumbo = new Gumbo(testHtml))
            {
                var list = gumbo.Document.Root.Children.OfType <Element>().ToList();
                Assert.AreEqual(GumboTag.GUMBO_TAG_HEAD, list[0].Tag);
                Assert.AreEqual("<head>", list[0].OriginalTag);
                var body = list[1].Children.OfType <Element>().ToList();
                Assert.AreEqual(GumboTag.GUMBO_TAG_TITLE, body[0].Tag);
                Assert.AreEqual(GumboTag.GUMBO_TAG_BASE, body[1].Tag);
                Assert.AreEqual(GumboTag.GUMBO_TAG_TT, body[2].Tag);
                Assert.AreEqual(GumboTag.GUMBO_TAG_UNKNOWN, body[3].Tag);
            }
        }
Exemple #7
0
        public static document createFromUTF8(string str, Idocument_container objPainter, context ctx, css user_styles = null)
        {
            var doc           = new document(objPainter, ctx); // Create litehtml::document
            var root_elements = new List <element>();

            using (var gumbo = new Gumbo.Gumbo(str))                  // parse document into GumboOutput
                doc.create_node(gumbo.Document.Root, root_elements);  // Create litehtml::elements.
            if (root_elements.Count != 0)
            {
                doc._root = root_elements.Back();
            }
            // Let's process created elements tree
            if (doc._root != null)
            {
                doc.container.get_media_features(doc._media);
                doc._root.apply_stylesheet(ctx.master_css); // apply master CSS
                doc._root.parse_attributes();               // parse elements attributes
                foreach (var css in doc._css)               // parse style sheets linked in document
                {
                    doc._styles.parse_stylesheet(css.text, css.baseurl, doc, !string.IsNullOrEmpty(css.media) ? media_query_list.create_from_string(css.media, doc) : null);
                }
                doc._styles.sort_selectors(); // Sort css selectors using CSS rules.
                if (doc._media_lists.Count != 0)
                {
                    doc.update_media_lists(doc._media);  // get current media features
                }
                doc._root.apply_stylesheet(doc._styles); // Apply parsed styles.
                if (user_styles != null)
                {
                    doc._root.apply_stylesheet(user_styles); // Apply user styles if any
                }
                doc._root.parse_styles();                    // Parse applied styles in the elements
                doc.fix_tables_layout();                     // Now the _tabular_elements is filled with tabular elements. We have to check the tabular elements for missing table elements and create the anonymous boxes in visual table layout
                doc._root.init();                            // Fanaly initialize elements
            }
            return(doc);
        }