Esempio n. 1
0
            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);
            }