private bool IsHtml(HtmlPortion current) { if (current.Is("<!--")) { return(true); } return(new Regex(@"^</?[a-zA-Z]").IsMatch(current.GetText(3))); }
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); }
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 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"); }
private static bool IsValid(HtmlPortion current) { return(current.Is("<!--")); }