コード例 #1
0
            public override bool Process(Token t, HtmlTreeBuilder tb)
            {
                switch (t.Type)
                {
                case TokenType.Character:
                    Token.Character c = t.AsCharacter();
                    if (c.Data.Equals(NullString))
                    {
                        tb.Error(this);
                        return(false);
                    }
                    else
                    {
                        tb.GetPendingTableCharacters().Add(c);
                    }
                    break;

                default:
                    if (tb.GetPendingTableCharacters().Count > 0)
                    {
                        foreach (Token.Character char2 in tb.GetPendingTableCharacters())
                        {
                            if (!IsWhitespace(char2))
                            {
                                // InTable anything else section:
                                tb.Error(this);

                                if (StringUtil.In(tb.CurrentElement.NodeName, "table", "tbody", "tfoot", "thead", "tr"))
                                {
                                    tb.SetFosterInserts(true);
                                    tb.Process(char2, InBody);
                                    tb.SetFosterInserts(false);
                                }
                                else
                                {
                                    tb.Process(char2, InBody);
                                }
                            }
                            else
                            {
                                tb.Insert(char2);
                            }
                        }
                        tb.NewPendingTableCharacters();
                    }
                    tb.Transition(tb.OriginalState);
                    return(tb.Process(t));
                }

                return(true);
            }
コード例 #2
0
            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));
            }