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); }
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"); }
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)); }
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); }
public string GetValue() { Start(_portion); var result = string.Empty; while (_portion.HasNext) { if (IsValueStart(_portion)) { return(result); } else { result += _portion.Char; _portion.Next(); } } throw new HtmlParseException("attribute value is not valid"); }
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"); }
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"); }