public static DomElement ParseDom(string html)
            {
                var node = new DomElement(null, null);

                foreach (var ev in LexedDomParser.Execute(html))
                {
                    switch (ev.Type)
                    {
                    case DomElementEventType.Push:
                        var child = new DomElement(node, ev.Fragment);
                        node.Children.Add(child);
                        node = child;
                        break;

                    case DomElementEventType.Child:
                        node.Children.Add(new DomElement(node, ev.Fragment));
                        break;

                    case DomElementEventType.Pop:
                        node = node.Parent;
                        break;
                    }
                }

                return(node);
            }
示例#2
0
        public static void AssertRoundTripsTo(this string rawHtml, string expectedHtml)
        {
            var actualHtml = LexedDomParser.Execute(rawHtml).WriteHtml();

            Assert.Equal(expectedHtml, actualHtml);
        }