private bool ExitTableBody(Token t, HtmlTreeBuilder tb) { if (!(tb.InTableScope("tbody") || tb.InTableScope("thead") || tb.InScope("tfoot"))) { // frag case tb.Error(this); return(false); } tb.ClearStackToTableBodyContext(); tb.Process(new Token.EndTag(tb.CurrentElement.NodeName)); // tbody, tfoot, thead return(tb.Process(t)); }
public override bool Process(Token t, HtmlTreeBuilder tb) { if (t.IsStartTag && StringSet.Create("caption table tbody tfoot thead tr td th").Contains(t.AsStartTag().Name)) { tb.Error(this); tb.Process(new Token.EndTag("select")); return(tb.Process(t)); } else if (t.IsEndTag && StringSet.Create("caption table tbody tfoot thead tr td th").Contains(t.AsEndTag().Name)) { tb.Error(this); if (tb.InTableScope(t.AsEndTag().Name)) { tb.Process(new Token.EndTag("select")); return(tb.Process(t)); } else { return(false); } } else { return(tb.Process(t, InSelect)); } }
private void CloseCell(HtmlTreeBuilder tb) { if (tb.InTableScope("td")) { tb.Process(new Token.EndTag("td")); } else { tb.Process(new Token.EndTag("th")); // only here if th or td in scope } }
public override bool Process(Token t, HtmlTreeBuilder tb) { if (t.IsEndTag && t.AsEndTag().Name.Equals("caption")) { Token.EndTag endTag = t.AsEndTag(); string name = endTag.Name; if (!tb.InTableScope(name)) { tb.Error(this); return(false); } else { tb.GenerateImpliedEndTags(); if (!tb.CurrentElement.NodeName.Equals("caption")) { tb.Error(this); } tb.PopStackToClose("caption"); tb.ClearFormattingElementsToLastMarker(); tb.Transition(InTable); } } else if ((t.IsStartTag && StringSet.Create("caption col colgroup tbody td tfoot th thead tr").Contains(t.AsStartTag().Name) || t.IsEndTag && t.AsEndTag().Name.Equals("table")) ) { tb.Error(this); bool processed = tb.Process(new Token.EndTag("caption")); if (processed) { return(tb.Process(t)); } } else if (t.IsEndTag && StringSet.Create("body col colgroup html tbody td tfoot th thead tr").Contains(t.AsEndTag().Name)) { tb.Error(this); return(false); } else { return(tb.Process(t, InBody)); } return(true); }
public override bool Process(Token t, HtmlTreeBuilder tb) { switch (t.Type) { case TokenType.StartTag: Token.StartTag startTag = t.AsStartTag(); string name = startTag.Name; if (name.Equals("tr")) { tb.ClearStackToTableBodyContext(); tb.Insert(startTag); tb.Transition(InRow); } else if (StringUtil.In(name, "th", "td")) { tb.Error(this); tb.Process(new Token.StartTag("tr")); return(tb.Process(startTag)); } else if (StringSet.Create("caption col colgroup tbody tfoot thead").Contains(name)) { return(ExitTableBody(t, tb)); } else { return(AnythingElse(t, tb)); } break; case TokenType.EndTag: Token.EndTag endTag = t.AsEndTag(); name = endTag.Name; if (StringUtil.In(name, "tbody", "tfoot", "thead")) { if (!tb.InTableScope(name)) { tb.Error(this); return(false); } else { tb.ClearStackToTableBodyContext(); tb.Pop(); tb.Transition(InTable); } } else if (name.Equals("table")) { return(ExitTableBody(t, tb)); } else if (StringSet.Create("body caption col colgroup html td th tr").Contains(name)) { tb.Error(this); return(false); } else { return(AnythingElse(t, tb)); } break; default: return(AnythingElse(t, tb)); } return(true); }
public override bool Process(Token t, HtmlTreeBuilder tb) { if (t.IsCharacter) { tb.NewPendingTableCharacters(); tb.MarkInsertionMode(); tb.Transition(InTableText); return(tb.Process(t)); } else if (t.IsComment) { tb.Insert(t.AsComment()); return(true); } else if (t.IsDoctype) { tb.Error(this); return(false); } else if (t.IsStartTag) { Token.StartTag startTag = t.AsStartTag(); string name = startTag.Name; switch (name) { case "caption": tb.ClearStackToTableContext(); tb.InsertMarkerToFormattingElements(); tb.Insert(startTag); tb.Transition(InCaption); break; case "colgroup": tb.ClearStackToTableContext(); tb.Insert(startTag); tb.Transition(InColumnGroup); break; case "col": tb.Process(new Token.StartTag("colgroup")); return(tb.Process(t)); case "table": tb.Error(this); bool processed = tb.Process(new Token.EndTag("table")); if (processed) // only ignored if in fragment { return(tb.Process(t)); } break; case "tbody": case "tfoot": case "thead": tb.ClearStackToTableContext(); tb.Insert(startTag); tb.Transition(InTableBody); break; case "td": case "th": case "tr": tb.Process(new Token.StartTag("tbody")); return(tb.Process(t)); case "style": case "script": return(tb.Process(t, InHead)); case "input": if (!startTag.Attributes["type"] .Equals("hidden", StringComparison.OrdinalIgnoreCase)) { return(AnythingElse(t, tb)); } else { tb.InsertEmpty(startTag); } break; case "form": tb.Error(this); if (tb.FormElement != null) { return(false); } else { HtmlElement form = tb.InsertEmpty(startTag); tb.FormElement = form; } break; default: return(AnythingElse(t, tb)); } } else if (t.IsEndTag) { Token.EndTag endTag = t.AsEndTag(); string name = endTag.Name; switch (name) { case "table": if (!tb.InTableScope(name)) { tb.Error(this); return(false); } else { tb.PopStackToClose("table"); } tb.ResetInsertionMode(); break; case "body": case "caption": case "col": case "colgroup": case "html": case "tbody": case "td": case "tfoot": case "th": case "thead": case "tr": tb.Error(this); return(false); default: 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)); }
public override bool Process(Token t, HtmlTreeBuilder tb) { if (t.IsEndTag) { Token.EndTag endTag = t.AsEndTag(); string name = endTag.Name; if (name.In("td", "th")) { if (!tb.InTableScope(name)) { tb.Error(this); tb.Transition(InRow); // might not be in scope if empty: <td /> and processing fake end tag return(false); } tb.GenerateImpliedEndTags(); if (!tb.CurrentElement.NodeName.Equals(name)) { tb.Error(this); } tb.PopStackToClose(name); tb.ClearFormattingElementsToLastMarker(); tb.Transition(InRow); } else if (StringUtil.In(name, "body", "caption", "col", "colgroup", "html")) { tb.Error(this); return(false); } else if (StringUtil.In(name, "table", "tbody", "tfoot", "thead", "tr")) { if (!tb.InTableScope(name)) { tb.Error(this); return(false); } CloseCell(tb); return(tb.Process(t)); } else { return(AnythingElse(t, tb)); } } else if (t.IsStartTag && StringSet.Create("caption col colgroup tbody td tfoot th thead tr").Contains(t.AsStartTag().Name)) { if (!(tb.InTableScope("td") || tb.InTableScope("th"))) { tb.Error(this); return(false); } CloseCell(tb); return(tb.Process(t)); } else { return(AnythingElse(t, tb)); } return(true); }
public override bool Process(Token t, HtmlTreeBuilder tb) { if (t.IsStartTag) { Token.StartTag startTag = t.AsStartTag(); string name = startTag.Name; if (StringUtil.In(name, "th", "td")) { tb.ClearStackToTableRowContext(); tb.Insert(startTag); tb.Transition(InCell); tb.InsertMarkerToFormattingElements(); } else if (StringSet.Create("caption col colgroup tbody tfoot thead tr").Contains(name)) { return(HandleMissingTr(t, tb)); } else { return(AnythingElse(t, tb)); } } else if (t.IsEndTag) { Token.EndTag endTag = t.AsEndTag(); string name = endTag.Name; if (name.Equals("tr")) { if (!tb.InTableScope(name)) { tb.Error(this); // frag return(false); } tb.ClearStackToTableRowContext(); tb.Pop(); // tr tb.Transition(InTableBody); } else if (name.Equals("table")) { return(HandleMissingTr(t, tb)); } else if (StringUtil.In(name, "tbody", "tfoot", "thead")) { if (!tb.InTableScope(name)) { tb.Error(this); return(false); } tb.Process(new Token.EndTag("tr")); return(tb.Process(t)); } else if (StringSet.Create("body caption col colgroup html td th").Contains(name)) { tb.Error(this); return(false); } else { return(AnythingElse(t, tb)); } } else { return(AnythingElse(t, tb)); } return(true); }