Exemplo n.º 1
0
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (t.IsCharacter())
     {
         tb.NewPendingTableCharacters();
         tb.MarkInsertionMode();
         tb.Transition(HtmlTreeBuilderState.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();
         if (name.Equals("caption"))
         {
             tb.ClearStackToTableContext();
             tb.InsertMarkerToFormattingElements();
             tb.Insert(startTag);
             tb.Transition(HtmlTreeBuilderState.InCaption);
         }
         else if (name.Equals("colgroup"))
         {
             tb.ClearStackToTableContext();
             tb.Insert(startTag);
             tb.Transition(HtmlTreeBuilderState.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(HtmlTreeBuilderState.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, HtmlTreeBuilderState.InHead);
         }
         else if (name.Equals("input"))
         {
             if (!string.Equals(startTag.attributes["type"], "hidden", StringComparison.OrdinalIgnoreCase))
             {
                 return this.AnythingElse(t, tb);
             }
             else
             {
                 tb.InsertEmpty(startTag);
             }
         }
         else if (name.Equals("form"))
         {
             tb.Error(this);
             if (tb.GetFormElement() != null)
             {
                 return false;
             }
             else
             {
                 tb.InsertForm(startTag, false);
             }
         }
         else
         {
             return this.AnythingElse(t, tb);
         }
         return true;
         // todo: check if should return processed http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#parsing-main-intable
     }
     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 this.AnythingElse(t, tb);
         }
         return true;
         // todo: as above todo
     }
     else if (t.IsEOF())
     {
         if (tb.CurrentElement().NodeName.Equals("html"))
         {
             tb.Error(this);
         }
         return true;
     }
     // stops parsing
     return this.AnythingElse(t, tb);
 }