public override bool Process(Token t, TreeBuilder tb) { switch (t.Type) { case Token.TokenType.Character: Token.Character c = t.AsCharacter(); if (c.Data.ToString().Equals(_nullString)) { tb.Error(this); return false; } else { tb.PendingTableCharacters.Add(c); } break; default: if (tb.PendingTableCharacters.Count > 0) { foreach (Token.Character character in tb.PendingTableCharacters) { if (!IsWhitespace(character)) { // InTable anything else section: tb.Error(this); if (StringUtil.In(tb.CurrentElement.NodeName, "table", "tbody", "tfoot", "thead", "tr")) { tb.IsFosterInserts = true; tb.Process(character, InBody); tb.IsFosterInserts = false; } else { tb.Process(character, InBody); } } else { tb.Insert(character); } } tb.NewPendingTableCharacters(); } tb.Transition(tb.OriginalState); return tb.Process(t); } return true; }
public override bool Process(Token t, TreeBuilder tb) { if (t.IsCharacter()) { tb.NewPendingTableCharacters(); tb.MarkInsertionMode(); tb.Transition(InTableText); return tb.Process(t); } else if (t.IsComment()) { tb.Insert(t.AsComment()); } else if (t.IsDoctype()) { tb.Error(this); return false; } else if (t.IsStartTag()) { Token.StartTag startTag = t.AsStartTag(); string name = startTag.Name(); if (name.Equals("caption")) { tb.ClearStackToTableContext(); tb.InsertMarkerToFormattingElements(); tb.Insert(startTag); tb.Transition(InCaption); } else if (name.Equals("colgroup")) { tb.ClearStackToTableContext(); tb.Insert(startTag); tb.Transition(InColumnGroup); } else if (name.Equals("col")) { tb.Process(new Token.StartTag("colgroup")); return tb.Process(t); } else if (StringUtil.In(name, "tbody", "tfoot", "thead")) { tb.ClearStackToTableContext(); tb.Insert(startTag); tb.Transition(InTableBody); } else if (StringUtil.In(name, "td", "th", "tr")) { tb.Process(new Token.StartTag("tbody")); return tb.Process(t); } else if (name.Equals("table")) { tb.Error(this); bool processed = tb.Process(new Token.EndTag("table")); if (processed) // only ignored if in fragment { return tb.Process(t); } } else if (StringUtil.In(name, "style", "script")) { return tb.Process(t, InHead); } else if (name.Equals("input")) { if (!startTag.Attributes["type"].Equals("hidden", StringComparison.InvariantCultureIgnoreCase)) { return AnythingElse(t, tb); } else { tb.InsertEmpty(startTag); } } else if (name.Equals("form")) { tb.Error(this); if (tb.FormElement != null) return false; else { Element form = tb.InsertEmpty(startTag); tb.FormElement = form; } } else { return AnythingElse(t, tb); } } else if (t.IsEndTag()) { Token.EndTag endTag = t.AsEndTag(); string name = endTag.Name(); if (name.Equals("table")) { if (!tb.InTableScope(name)) { tb.Error(this); return false; } else { tb.PopStackToClose("table"); } tb.ResetInsertionMode(); } else if (StringUtil.In(name, "body", "caption", "col", "colgroup", "html", "tbody", "td", "tfoot", "th", "thead", "tr")) { tb.Error(this); return false; } else { return AnythingElse(t, tb); } } else if (t.IsEOF()) { if (tb.CurrentElement.NodeName.Equals("html")) tb.Error(this); return true; // stops parsing } return AnythingElse(t, tb); }