Exemplo n.º 1
0
 public override bool Process(Token t, TreeBuilder tb)
 {
     if (t.IsStartTag() && StringUtil.In(t.AsStartTag().Name(), "caption", "table", "tbody", "tfoot", "thead", "tr", "td", "th"))
     {
         tb.Error(this);
         tb.Process(new Token.EndTag("select"));
         return tb.Process(t);
     }
     else if (t.IsEndTag() && StringUtil.In(t.AsEndTag().Name(), "caption", "table", "tbody", "tfoot", "thead", "tr", "td", "th"))
     {
         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);
     }
 }
Exemplo n.º 2
0
            public override bool Process(Token t, TreeBuilder tb)
            {
                if (t.IsEndTag())
                {
                    Token.EndTag endTag = t.AsEndTag();
                    String name = endTag.Name();

                    if (StringUtil.In(name, "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() &&
                        StringUtil.In(t.AsStartTag().Name(),
                                "caption", "col", "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"))
                {
                    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;
            }
Exemplo n.º 3
0
 private void CloseCell(TreeBuilder 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
     }
 }
Exemplo n.º 4
0
            public override bool Process(Token t, TreeBuilder 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 (StringUtil.In(name, "caption", "col", "colgroup", "tbody", "tfoot", "thead", "tr"))
                    {
                        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 (StringUtil.In(name, "body", "caption", "col", "colgroup", "html", "td", "th"))
                    {
                        tb.Error(this);
                        return false;
                    }
                    else
                    {
                        return AnythingElse(t, tb);
                    }
                }
                else
                {
                    return AnythingElse(t, tb);
                }
                return true;
            }
Exemplo n.º 5
0
 private bool ExitTableBody(Token t, TreeBuilder 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);
 }
Exemplo n.º 6
0
 public override bool Process(Token t, TreeBuilder tb)
 {
     switch (t.Type)
     {
         case Token.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 (StringUtil.In(name, "caption", "col", "colgroup", "tbody", "tfoot", "thead"))
             {
                 return ExitTableBody(t, tb);
             }
             else
             {
                 return AnythingElse(t, tb);
             }
             break;
         case Token.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 (StringUtil.In(name, "body", "caption", "col", "colgroup", "html", "td", "th", "tr"))
             {
                 tb.Error(this);
                 return false;
             }
             else
             {
                 return AnythingElse(t, tb);
             }
             break;
         default:
             return AnythingElse(t, tb);
     }
     return true;
 }
Exemplo n.º 7
0
            public override bool Process(Token t, TreeBuilder 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() &&
                    StringUtil.In(t.AsStartTag().Name(), "caption", "col", "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr") ||
                    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() && StringUtil.In(t.AsEndTag().Name(),
                      "body", "col", "colgroup", "html", "tbody", "td", "tfoot", "th", "thead", "tr"))
                {
                    tb.Error(this);
                    return false;
                }
                else
                {
                    return tb.Process(t, InBody);
                }
                return true;
            }
Exemplo n.º 8
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);
            }