示例#1
0
        public static IEnumerable <INode> Partial(string htmlRaw, DocInfo info = null)
        {
            htmlRaw = EscapeHtml(htmlRaw);
            var htmlPortion = new HtmlPortion(htmlRaw);

            htmlPortion.Jump();
            return(new HtmlParser(info).Parse(htmlPortion));
        }
示例#2
0
 public IEnumerable <INode> Parse(HtmlPortion portion)
 {
     return(Parse(portion,
                  new IHtmlParser[]
                  { new CommentParser(this.Info),
                    new ScriptParser(this.Info),
                    new StyleParser(this.Info),
                    new TagParser(this.Info),
                    new EndTagParser(),
                    new TextParser(this.Info) }));
 }
示例#3
0
        public HtmlDocument Parse(string htmlRaw)
        {
            htmlRaw = EscapeHtml(htmlRaw);
            var htmlDocument = new HtmlDocument(this.Info);
            var htmlPortion  = new HtmlPortion(htmlRaw.TrimStart());

            foreach (var node in Parse(htmlPortion, new IHtmlParser[] { new DocumentTypeParser(), new TagParser(this.Info), new EndTagParser() }))
            {
                htmlDocument.Append(node);
            }
            return(htmlDocument);
        }
示例#4
0
        public IEnumerable <INode> Parse(HtmlPortion portion, IHtmlParser[] parsers)
        {
            Func <HtmlPortion, IHtmlParser[], INode> fn = (p, pa) =>
            {
                foreach (var parser in parsers)
                {
                    if (portion.IsEnd)
                    {
                        return(null);
                    }
                    var result = parser.Parse(this, portion);
                    if (result == null)
                    {
                        continue;
                    }
                    return(result);
                }
                return(null);
            };

            while (portion.HasNext)
            {
                if (portion.IsWhiteSpace)
                {
                    portion.Next();
                    continue;
                }
                var result = fn(portion, parsers);
                if (result != null)
                {
                    yield return(result);

                    if (result is IParseBreak)
                    {
                        yield break;
                    }
                }
                else
                {
                    portion.Jump();
                }
            }
        }
示例#5
0
 public AttributeParseResult GetAttribute(HtmlPortion portion)
 {
     return(new AttributesParser().Parse(portion));
 }