protected override bool HandleCore(TokenParser context, ICollection <Token> tokens, char ch) { if (ch == '>') { Token token = context.SwitchState(TokenType.Text, new TextHandler()); tokens.Add(token); if (token.Type == TokenType.OpenTag && (token.Value == "script" || token.Value == "style")) { tokens.Add(context.SwitchState(TokenType.Text, new CDataHandler(string.Format("</{0}", token.Value)))); } return(true); } if (ch == '/' || Char.IsWhiteSpace(ch)) { var handler = new AttibuteNameHandler(); Token token = context.SwitchState(TokenType.AttributeName, handler); if (token.Type == TokenType.OpenTag && (token.Value == "script" || token.Value == "style")) { handler.ReplaceNextTagOrTextTokenWithCData = string.Format("</{0}", token.Value); } tokens.Add(token); return(true); } return(false); }
protected override bool HandleCore(TokenParser context, ICollection<Token> tokens, char ch) { if (ch == '>') { Token token = context.SwitchState(TokenType.Text, new TextHandler()); tokens.Add(token); if (token.Type == TokenType.OpenTag && (token.Value == "script" || token.Value == "style")) { tokens.Add(context.SwitchState(TokenType.Text, new CDataHandler(string.Format("</{0}", token.Value)))); } return true; } if (ch == '/' || Char.IsWhiteSpace(ch)) { var handler = new AttibuteNameHandler(); Token token = context.SwitchState(TokenType.AttributeName, handler); if (token.Type == TokenType.OpenTag && (token.Value == "script" || token.Value == "style")) { handler.ReplaceNextTagOrTextTokenWithCData = string.Format("</{0}", token.Value); } tokens.Add(token); return true; } return false; }
protected override bool HandleCore(TokenParser context, ICollection<Token> tokens, char ch) { if (ch == '>') { tokens.Add(string.IsNullOrEmpty(ReplaceNextTagOrTextTokenWithCData) ? context.SwitchState(TokenType.Text, new TextHandler()) : context.SwitchState(TokenType.Text, new CDataHandler(ReplaceNextTagOrTextTokenWithCData))); return true; } return false; }
protected override bool HandleCore(TokenParser context, ICollection <Token> tokens, char ch) { if (ch == '>') { tokens.Add(string.IsNullOrEmpty(ReplaceNextTagOrTextTokenWithCData) ? context.SwitchState(TokenType.Text, new TextHandler()) : context.SwitchState(TokenType.Text, new CDataHandler(ReplaceNextTagOrTextTokenWithCData))); return(true); } return(false); }
protected override bool HandleCore(TokenParser context, ICollection <Token> tokens, char ch) { if (state == State.AttributeValueBegin) { if (ch == '"' || ch == '\'') { tokens.Add(context.SwitchState(TokenType.AttributeValue, new AttibuteValueHandler(ch) { ReplaceNextTagOrTextTokenWithCData = ReplaceNextTagOrTextTokenWithCData })); return(true); } if (!Char.IsWhiteSpace(ch)) { tokens.Add(context.SwitchState(TokenType.AttributeValue, new AttibuteValueHandler(' ', '\t', '\r', '\x00a0', '\x0085') { ReplaceNextTagOrTextTokenWithCData = ReplaceNextTagOrTextTokenWithCData })); return(false); } return(true); } if (ch == '=') { state = State.AttributeValueBegin; return(true); } if (ch == '/' || Char.IsWhiteSpace(ch)) { tokens.Add(context.SwitchState(TokenType.AttributeName, new AttibuteNameHandler { ReplaceNextTagOrTextTokenWithCData = ReplaceNextTagOrTextTokenWithCData })); return(true); } return(base.HandleCore(context, tokens, ch)); }
protected override bool HandleCore(TokenParser context, ICollection<Token> tokens, char ch) { if (state == State.AttributeValueBegin) { if (ch == '"' || ch == '\'') { tokens.Add(context.SwitchState(TokenType.AttributeValue, new AttibuteValueHandler(ch) { ReplaceNextTagOrTextTokenWithCData = ReplaceNextTagOrTextTokenWithCData })); return true; } if (!Char.IsWhiteSpace(ch)) { tokens.Add(context.SwitchState(TokenType.AttributeValue, new AttibuteValueHandler(' ', '\t', '\r', '\x00a0', '\x0085') { ReplaceNextTagOrTextTokenWithCData = ReplaceNextTagOrTextTokenWithCData })); return false; } return true; } if (ch == '=') { state = State.AttributeValueBegin; return true; } if (ch == '/' || Char.IsWhiteSpace(ch)) { tokens.Add(context.SwitchState(TokenType.AttributeName, new AttibuteNameHandler { ReplaceNextTagOrTextTokenWithCData = ReplaceNextTagOrTextTokenWithCData })); return true; } return base.HandleCore(context, tokens, ch); }
protected override bool HandleCore(TokenParser context, ICollection <Token> tokens, char ch) { if (chars.Contains(ch)) { tokens.Add(context.SwitchState(TokenType.AttributeName, new AttibuteNameHandler { ReplaceNextTagOrTextTokenWithCData = ReplaceNextTagOrTextTokenWithCData })); return(true); } return(base.HandleCore(context, tokens, ch)); }
protected override bool HandleCore(TokenParser context, ICollection<Token> tokens, char ch) { if (chars.Contains(ch)) { tokens.Add(context.SwitchState(TokenType.AttributeName, new AttibuteNameHandler { ReplaceNextTagOrTextTokenWithCData = ReplaceNextTagOrTextTokenWithCData })); return true; } return base.HandleCore(context, tokens, ch); }
protected override bool HandleCore(TokenParser context, ICollection<Token> tokens, char ch) { if (closeToken[index] == ch) { index++; if (index >= closeToken.Length) { tokens.Add(context.SwitchState(TokenType.CloseTag, new TagHandler())); context.TokenBuilder.Append(closeToken.Substring(2)); } return true; } if (index > 0) { context.TokenBuilder.Append(closeToken.Substring(0, index)); index = 0; } return false; }
protected override bool HandleCore(TokenParser context, ICollection <Token> tokens, char ch) { if (closeToken[index] == ch) { index++; if (index >= closeToken.Length) { tokens.Add(context.SwitchState(TokenType.CloseTag, new TagHandler())); context.TokenBuilder.Append(closeToken.Substring(2)); } return(true); } if (index > 0) { context.TokenBuilder.Append(closeToken.Substring(0, index)); index = 0; } return(false); }
protected override bool HandleCore(TokenParser context, ICollection <Token> tokens, char ch) { if (state == State.Default) { if (ch == '<') { state = State.WaitForTagOrComment; return(true); } return(false); } if (state == State.WaitForTagOrComment) { if (ch == '/') { tokens.Add(context.SwitchState(TokenType.CloseTag, new TagHandler())); return(true); } if (ch == '!') { state = State.WaitForMinus; return(true); } if (!char.IsLetter(ch)) { state = State.Default; context.TokenBuilder.Append('<'); return(false); } tokens.Add(context.SwitchState(TokenType.OpenTag, new TagHandler())); return(false); } if (state == State.WaitForMinus) { if (ch == '>') { tokens.Add(context.SwitchState(TokenType.Comment, new CommentHandler())); tokens.Add(context.SwitchState(TokenType.Text, new TextHandler())); return(true); } if (ch == '-') { state = State.WaitForSecondMinus; return(true); } state = State.Default; context.TokenBuilder.Append("<!"); return(false); } if (state == State.WaitForSecondMinus) { if (ch == '-') { tokens.Add(context.SwitchState(TokenType.Comment, new CommentHandler())); return(true); } state = State.Default; context.TokenBuilder.Append("<!-"); return(false); } return(false); }