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)); }
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)); }
private Dom.Node ParseText() { return(Dom.CreateText(ConsumeWhile(c => c != '<'))); }