Ejemplo n.º 1
0
 static void ReadNext(ParserContext context)
 {
     while (!context.EndOfString)
     {
         Match match;
         if (context.InScriptTag)
         {
             match = RxNextScriptCloseToken.Match(context.Html, context.Index);
             context.InScriptTag = false;
         }
         else
         {
             match = RxNextToken.Match(context.Html, context.Index);
         }
         if (match.Success)
         {
             var len = match.Index - context.Index;
             if (len > 0)
             {
                 var str = context.Html.Substring(context.Index, len);
                 context.Tokens.Add(new HtmlParserToken {
                     Type = TokenType.Text, A = context.AdjustForWhitespace(str), Raw = str
                 });
                 context.Index += len;
             }
             if (match.Groups["xmldecl"].Success)
             {
                 ReadXmlDeclaration(context);
             }
             else if (match.Groups["doctype"].Success)
             {
                 ReadDocTypeDeclaration(context);
             }
             else if (match.Groups["comment"].Success)
             {
                 ReadComment(context);
             }
             else if (match.Groups["close"].Success)
             {
                 ReadCloseElement(context);
             }
             else if (match.Groups["cdata"].Success)
             {
                 ReadCdata(context);
             }
             else
             {
                 ReadElement(context);
             }
         }
         else
         {
             var str = context.Html.Substring(context.Index);
             context.Tokens.Add(new HtmlParserToken {
                 Type = TokenType.Text, A = context.AdjustForWhitespace(str), Raw = str
             });
             return;
         }
     }
 }
Ejemplo n.º 2
0
        private static void ReadCloseElement(ParserContext context)
        {
            var match = RxReadCloseAttribute.Match(context.Html, context.Index);

            if (!match.Success)
            {
                var str = context.Html.Substring(context.Index);
                context.Tokens.Add(new HtmlParserToken {
                    Type = TokenType.Text, A = context.AdjustForWhitespace(str), Raw = str
                });
                context.Index = context.Html.Length;
            }
            else
            {
                var newToken = new HtmlParserToken {
                    Type = TokenType.CloseElement, Raw = match.Value, A = match.Groups["name"].Value
                };
                context.Tokens.Add(newToken);
                //HACK there might be a tag inside of a tag (Incorrectly closed tag) like </strong</td>
                //If we find this, we are going to adjust
                if (newToken.A.IndexOf("<") > -1)
                {
                    var index = match.Value.Substring(2).IndexOf("<");
                    newToken.A     = newToken.A.Substring(0, index);
                    context.Index += index + 2;
                }
                else
                {
                    context.Index += match.Length;
                }
            }
        }
Ejemplo n.º 3
0
		static void ReadNext(ParserContext context)
		{
			while(!context.EndOfString)
			{
				Match match;
				if (context.InScriptTag)
				{
					match = RxNextScriptToken.Match(context.Html, context.Index);

					if (match.Groups["close"].Success)
					{
						context.InScriptTag = false;
					}
				}
				else
				{
					match = RxNextToken.Match(context.Html, context.Index);
				}

				if(match.Success)
				{
					var len = match.Index - context.Index;
					if(len > 0)
					{
						var str = context.Html.Substring(context.Index, len);
						context.Tokens.Add(new HtmlParserToken { Type = TokenType.Text, A = context.AdjustForWhitespace(str), Raw = str });
						context.Index += len;
					}
					if(match.Groups["xmldecl"].Success)
						ReadXmlDeclaration(context);
					else if(match.Groups["doctype"].Success)
						ReadDocTypeDeclaration(context);
					else if(match.Groups["comment"].Success)
						ReadComment(context);
					else if(match.Groups["close"].Success)
						ReadCloseElement(context);
					else if(match.Groups["cdata"].Success)
						ReadCdata(context);
					else if (match.Groups["conditional"].Success)
						ReadConditional(context);
					else
						ReadElement(context);
				}
				else
				{
					var str = context.Html.Substring(context.Index);
					context.Tokens.Add(new HtmlParserToken { Type = TokenType.Text, A = context.AdjustForWhitespace(str), Raw = str });
					return;
				}
			}
		}
Ejemplo n.º 4
0
        private static void ReadCloseElement(ParserContext context)
        {
            var match = RxReadCloseAttribute.Match(context.Html, context.Index);

            if (!match.Success)
            {
                var str = context.Html.Substring(context.Index);
                context.Tokens.Add(new HtmlParserToken {
                    Type = TokenType.Text, A = context.AdjustForWhitespace(str), Raw = str
                });
                context.Index = context.Html.Length;
            }
            else
            {
                context.Tokens.Add(new HtmlParserToken {
                    Type = TokenType.CloseElement, Raw = match.Value, A = match.Groups["name"].Value
                });
                context.Index += match.Length;
            }
        }
Ejemplo n.º 5
0
		private static void ReadCloseElement(ParserContext context)
		{
			var match = RxReadCloseAttribute.Match(context.Html, context.Index);
			if(!match.Success)
			{
				var str = context.Html.Substring(context.Index);
				context.Tokens.Add(new HtmlParserToken { Type = TokenType.Text, A = context.AdjustForWhitespace(str), Raw = str });
				context.Index = context.Html.Length;
			}
			else
			{
				var newToken = new HtmlParserToken { Type = TokenType.CloseElement, Raw = match.Value, A = match.Groups["name"].Value };
				context.Tokens.Add(newToken);
				//HACK there might be a tag inside of a tag (Incorrectly closed tag) like </strong</td>
				//If we find this, we are going to adjust
				if (newToken.A.IndexOf("<") > -1)
				{
					var index = match.Value.Substring(2).IndexOf("<");
					newToken.A = newToken.A.Substring(0, index);
					context.Index += index + 2;
				}
				else
				{
					context.Index += match.Length;
				}
			}
		}
Ejemplo n.º 6
0
 private static void ReadCloseElement(ParserContext context)
 {
     var match = RxReadCloseAttribute.Match(context.Html, context.Index);
     if(!match.Success)
     {
         var str = context.Html.Substring(context.Index);
         context.Tokens.Add(new HtmlParserToken { Type = TokenType.Text, A = context.AdjustForWhitespace(str), Raw = str });
         context.Index = context.Html.Length;
     }
     else
     {
         context.Tokens.Add(new HtmlParserToken { Type = TokenType.CloseElement, Raw = match.Value, A = match.Groups["name"].Value });
         context.Index += match.Length;
     }
 }