Beispiel #1
0
        public static Dom.Node Parse(string source)
        {
            var nodes = new Parser(0, source).ParseNodes();

            if (nodes.Count == 1)
            {
                return(nodes[0]);
            }

            return(Dom.CreateElement("html", new Dictionary <string, string>(), nodes));
        }
Beispiel #2
0
            private Dom.Node ParseElement()
            {
                Trace.Assert(ConsumeChar() == '<');
                var tagName = ParseTagName();
                var attrs   = ParseAttributes();

                Trace.Assert(ConsumeChar() == '>');

                var children = ParseNodes();

                Trace.Assert(ConsumeChar() == '<');
                Trace.Assert(ConsumeChar() == '/');
                Trace.Assert(ParseTagName() == tagName);
                Trace.Assert(ConsumeChar() == '>');

                return(Dom.CreateElement(tagName, attrs, children));
            }
Beispiel #3
0
 private Dom.Node ParseText()
 {
     return(Dom.CreateText(ConsumeWhile(c => c != '<')));
 }