コード例 #1
0
        private static string GetAttributes(IHtmlContent content)
        {
            var escapeHtml    = new EscapeStringHtmlContent(content);
            var beginPosition = content.Index;
            var lastPosition  = beginPosition;

            while (escapeHtml.Next())
            {
                if (content.CurrentChar == '/' && content.NextChar == '>')
                {
                    lastPosition = content.Index;
                    break;
                }
                if (content.CurrentChar == '>')
                {
                    lastPosition = content.Index;
                    break;
                }
            }

            var isCatched = beginPosition != lastPosition;

            if (!isCatched)
            {
                return(content.Content.ToString().Substring(beginPosition, content.Content.Length - beginPosition));
            }

            beginPosition = beginPosition < 0 ? 0 : beginPosition; // this function is used for getAttributes. so it can gets from -1 position
            // if(beginPosition < 0 ) throw new ParseErrorException($"could not seperate attributes from element;beginPosition:[{beginPosition}] content [{content.Content}]");
            var result = content.RootContent.Substring(beginPosition, lastPosition - beginPosition);

            return(result);
        }
コード例 #2
0
        private IEnumerable <IHtmlMarkup> GetResult(ITag mainTag, IHtmlContent content)
        {
            yield return(mainTag);

            content.Outstrip();
            var  escapedStringHtml = new EscapeStringHtmlContent(content);
            var  position          = content.Index;
            bool isFounded         = false;

            while (escapedStringHtml.Next())
            {
                if (!this.IsEndTag(mainTag, escapedStringHtml.Content))
                {
                    continue;
                }
                var result = this._elementSeperator.Parse(escapedStringHtml);
                if (!result.IsSuccess)
                {
                    continue;
                }
                var first = result.Result.First();
                if (first is EndTag endTag)
                {
                    var isMainEndTag = endTag.Name.Equals(mainTag.Name, StringComparison.OrdinalIgnoreCase);
                    if (!isMainEndTag)
                    {
                        continue;
                    }
                    if (escapedStringHtml.IsQuotes(result.From + content.From))
                    {
                        continue;
                    }
                    isFounded = true;
                    yield return(new RawText(content.RootContent.Substring(position, result.From)));

                    yield return(endTag);

                    break;
                }
            }

            if (!isFounded)
            {
                yield return(new RawText(escapedStringHtml.Content.ToString()));
            }
        }