コード例 #1
0
ファイル: StyleParser.cs プロジェクト: hknyuc/RestHttpClient
        public INode Parse(HtmlParser parser, HtmlPortion current)
        {
            if (!IsStyle(current))
            {
                return(null);
            }

            var attr         = parser.GetAttribute(current);
            var end          = current.StartIndexOf(new Regex(@"</style\s*>"));
            var contentIndex = end - current.Current;

            current.Next();
            var content = current.Substring(contentIndex);

            current.Jump(contentIndex);
            if (attr.IsSingle)
            {
                return(new StyleTag("<style", attr.Attributes, "", _info));
            }
            var result = new StyleTag("style", attr.Attributes, content, _info);

            current.Jump(current.IndexOf(new Regex(@"</style\s*>")));
            current.Jump();
            return(result);
        }
コード例 #2
0
 public INode Parse(HtmlParser parser, HtmlPortion current)
 {
     if (new Regex(@"</[a-zA-Z]").IsMatch(current.GetText(3)))
     {
         return(new IgnoreElement());
     }
     return(null);
 }
コード例 #3
0
 public static bool IsValueStart(HtmlPortion portion)
 {
     if ((portion.Char == '\'' || portion.Char == '"') && portion.BeforeChar != '\\')
     {
         return(true);
     }
     return(false);
 }
コード例 #4
0
 private bool IsHtml(HtmlPortion current)
 {
     if (current.Is("<!--"))
     {
         return(true);
     }
     return(new Regex(@"^</?[a-zA-Z]").IsMatch(current.GetText(3)));
 }
コード例 #5
0
ファイル: StyleParser.cs プロジェクト: hknyuc/RestHttpClient
        private static bool IsStyle(HtmlPortion current)
        {
            //var with = current.NextWith;
            //if (with.Contains("scri") && !current.Is("script") && current.Current > 60000)
            //{
            //    var seven = current.GetText(7);
            //    var result2 = current.Is("<script");
            //}
            var result = current.Is("<style");

            return(result);
        }
コード例 #6
0
        public INode Parse(HtmlParser parser, HtmlPortion current)
        {
            if (current.IsStartTagChar() && current.IsNext('!'))
            {
                var text = current.Substring(' ');
                var t    = text.ToLower() == "<!doctype ";
                if (t)
                {
                    var index = current.IndexOf('>');
                    current.Jump(index);
                    current.Next();
                    return(new DocumentTypeTag());
                }
            }

            return(null);
        }
コード例 #7
0
 private char Start(HtmlPortion portion)
 {
     while (portion.HasNext)
     {
         if (portion.IsWhiteSpace)
         {
             portion.Next();
             continue;
         }
         if (!IsValueStart(portion))
         {
             throw new HtmlParseException("attribute value is not valid");
         }
         var result = portion.Char;
         portion.Next();
         return(result);
     }
     throw new HtmlParseException("attribute value is not valid");
 }
コード例 #8
0
        public INode Parse(HtmlParser parser, HtmlPortion current)
        {
            if (!IsValid(current))
            {
                return(null);
            }
            current.Next(4);
            var content = string.Empty;

            while (current.HasNext)
            {
                if (current.Is("-->"))
                {
                    current.Next(2);
                    break;
                }
                content += current.Char;
                current.Next();
            }
            current.Jump();
            return(new Comment(content, _info));
        }
コード例 #9
0
        public INode Parse(HtmlParser parser, HtmlPortion current)
        {
            if (char.IsWhiteSpace(current.Char))
            {
                return(null);
            }
            if (IsHtml(current))
            {
                return(null);
            }
            var result = string.Empty;

            while (current.HasNext)
            {
                if (IsHtml(current))
                {
                    return(Return(result));
                }

                result += current.Char;
                current.Next();
            }
            throw new HtmlParseException("text is not valid for parse");
        }
コード例 #10
0
 private bool IsValid(HtmlPortion current)
 {
     return(current.Char == '<' && current.NextChar != '/');
 }
コード例 #11
0
 private static int GetEndSingleIndex(HtmlPortion portion)
 {
     return(portion.IndexOf(new Regex(@"^\s*/>")));
 }
コード例 #12
0
 private static bool IsEnd(HtmlPortion portion)
 {
     return(portion.IndexOf(new Regex(@"^\s*>")) >= 0);
 }
コード例 #13
0
 internal AttributeStringProcess(HtmlPortion portion)
 {
     _portion = portion;
 }
コード例 #14
0
        public AttributeParseResult Parse(HtmlPortion current)
        {
            if (!IsValid(current))
            {
                throw new HtmlParseException("tag is not valid");
            }
            current.Next();
            var attributes = new Attributes();
            var attribute  = new AttributeSingle();

            while (current.HasNext)
            {
                if (current.IsWhiteSpace)
                {
                    if (attribute.ValueEmpty && !attribute.KeyEmpty)
                    {
                        attributes.Add(attribute.Pull());
                    }
                    current.Jump();
                    continue;
                }

                if (current.Char == '/' && current[current.NextNonWhiteSpace()] == '>')
                {
                    var next = current.NextNonWhiteSpace();
                    current.Jump(next);
                    if (!attributes.Any())
                    {
                        if (attribute.ValueEmpty && !attribute.KeyEmpty)
                        {
                            attributes.Add(attribute.Pull());
                        }
                        if (!attributes.Any())
                        {
                            throw new HtmlParseException("tag is not valid");
                        }
                    }
                    var tagName = attributes.First().Key;
                    return(new AttributeParseResult(true, tagName, new Attributes(attributes.Skip(1).ToArray())));
                }

                if (current.Char == '>')
                {
                    if (attributes.IsEmpty)
                    {
                        if (!attribute.Empty)
                        {
                            attributes.Add(attribute.Pull());
                        }
                    }
                    if (attributes.IsEmpty)
                    {
                        throw new HtmlParseException("tag is not valid");
                    }
                    var tagName = attributes.First().Key;
                    return(new AttributeParseResult(false, tagName, new Attributes(attributes.Skip(1).ToArray())));
                }

                if (current.Is('=') && AttributeStringProcess.IsValueStart(current.NextNonWhiteSpaceChar()))
                {
                    current.Jump();
                    attribute.SetType(AttributeNameValue.Value);
                    attribute.Insert(new AttributeStringProcess(current).GetValue());
                    attributes.Add(attribute.Pull());
                    attribute.SetType(AttributeNameValue.Key);
                    current.Jump();
                    continue;
                }
                attribute.Insert(current.Char);
                current.Next();
            }
            throw new HtmlParseException("tag is not valid");
        }
コード例 #15
0
 private static bool IsValid(HtmlPortion current)
 {
     return(current.Is("<!--"));
 }