Exemplo n.º 1
0
        private IEnumerable <IHtmlMarkup> GetTagElement(IHtmlContent content, RefIndex refIndex)
        {
            var matchResult = _startRegex.Match(content.Content.ToString());
            var name        = matchResult.Groups[1].Value;

            refIndex.Index = matchResult.Index;
            if (content.CurrentChar == '>')
            {
                yield return(new Tag(content.Content.ToString(), name, Array.Empty <IAttribute>(), GetElements(name, CloneContent(content))));

                yield break;
            }

            var          beginPosition  = refIndex.Index + (matchResult.Length) + content.From; // {from}this is test code <div{beginPosition} name='4'>{index}
            IHtmlContent currentContent = content;

            if (beginPosition < content.Index)
            {
                currentContent =
                    new HtmlContent(content.RootContent.Substring(beginPosition, content.Index - beginPosition));
            }
            var attributes = new AttributeCollection(GetAttributes(currentContent)).ToArray();

            yield return(new Tag(content.Content.ToString(), name, attributes, GetElements(name, CloneContent(currentContent))));
        }
Exemplo n.º 2
0
        private IEnumerable <IHtmlMarkup> GetEndTagElement(IHtmlContent content, RefIndex refIndex)
        {
            var match = _endRegex.Match(content.Content.ToString());

            refIndex.Index = match.Index;
            yield return(new EndTag(content.Content.ToString(), match.Groups[1].Value));
        }
Exemplo n.º 3
0
        public ParseResult Parse(IHtmlContent content)
        {
            if (!content.Content.AnyFrequence('<'))
            {
                return(new ParseResult());
            }
            var fr       = content.Content.GetFrequence('<');
            var isEndTag = this.IsEndTag(content.Content.ToString(), fr.LastIndex);
            var refIndex = new RefIndex();

            if (isEndTag)
            {
                return(new ParseResult(this.GetEndTagElement(content, refIndex).ToArray(), refIndex.Index));
            }
            var isTagElement = this.IsTagElement(content.Content.ToString(), fr.LastIndex);

            if (isTagElement)
            {
                return(new ParseResult(this.GetTagElement(content, refIndex).ToArray(), refIndex.Index));
            }
            return(new ParseResult());
        }