Exemple #1
0
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (t.IsDoctype())
     {
         tb.Error(this);
         return false;
     }
     else if (t.IsComment())
     {
         tb.Insert(t.AsComment());
     }
     else if (HtmlTreeBuilderState.IsWhitespace(t))
     {
         return true;
         // ignore whitespace
     }
     else if (t.IsStartTag() && t.AsStartTag().Name().Equals("html"))
     {
         tb.Insert(t.AsStartTag());
         tb.Transition(HtmlTreeBuilderState.BeforeHead);
     }
     else if (t.IsEndTag() && (StringUtil.In(t.AsEndTag().Name(), "head", "body", "html", "br")))
     {
         return this.AnythingElse(t, tb);
     }
     else if (t.IsEndTag())
     {
         tb.Error(this);
         return false;
     }
     else
     {
         return this.AnythingElse(t, tb);
     }
     return true;
 }
Exemple #2
0
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (HtmlTreeBuilderState.IsWhitespace(t))
     {
         tb.Insert(t.AsCharacter());
     }
     else if (t.IsComment())
     {
         tb.Insert(t.AsComment());
     }
     else if (t.IsDoctype())
     {
         tb.Error(this);
     }
     else if (t.IsStartTag())
     {
         Token.StartTag startTag = t.AsStartTag();
         string name = startTag.Name();
         if (name.Equals("html"))
         {
             return tb.Process(t, HtmlTreeBuilderState.InBody);
         }
         else if (name.Equals("body"))
         {
             tb.Insert(startTag);
             tb.FramesetOk(false);
             tb.Transition(HtmlTreeBuilderState.InBody);
         }
         else if (name.Equals("frameset"))
         {
             tb.Insert(startTag);
             tb.Transition(HtmlTreeBuilderState.InFrameset);
         }
         else if (StringUtil.In(name, "base", "basefont", "bgsound", "link", "meta", "noframes", "script", "style", "title"))
         {
             tb.Error(this);
             Element head = tb.GetHeadElement();
             tb.Push(head);
             tb.Process(t, HtmlTreeBuilderState.InHead);
             tb.RemoveFromStack(head);
         }
         else if (name.Equals("head"))
         {
             tb.Error(this);
             return false;
         }
         else
         {
             this.AnythingElse(t, tb);
         }
     }
     else if (t.IsEndTag())
     {
         if (StringUtil.In(t.AsEndTag().Name(), "body", "html"))
         {
             this.AnythingElse(t, tb);
         }
         else
         {
             tb.Error(this);
             return false;
         }
     }
     else
     {
         this.AnythingElse(t, tb);
     }
     return true;
 }
Exemple #3
0
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (HtmlTreeBuilderState.IsWhitespace(t))
     {
         tb.Insert(t.AsCharacter());
     }
     else if (t.IsComment())
     {
         tb.Insert(t.AsComment());
     }
     else if (t.IsDoctype())
     {
         tb.Error(this);
         return false;
     }
     else if (t.IsStartTag() && t.AsStartTag().Name().Equals("html"))
     {
         return tb.Process(t, HtmlTreeBuilderState.InBody);
     }
     else if (t.IsEndTag() && t.AsEndTag().Name().Equals("html"))
     {
         tb.Transition(HtmlTreeBuilderState.AfterAfterFrameset);
     }
     else if (t.IsStartTag() && t.AsStartTag().Name().Equals("noframes"))
     {
         return tb.Process(t, HtmlTreeBuilderState.InHead);
     }
     else if (t.IsEOF())
     {
     }
     else
     {
         // cool your heels, we're complete
         tb.Error(this);
         return false;
     } return true;
 }
Exemple #4
0
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (t.IsDoctype())
     {
         tb.Error(this);
     }
     else if (t.IsStartTag() && t.AsStartTag().Name().Equals("html"))
     {
         return tb.Process(t, HtmlTreeBuilderState.InBody);
     }
     else if (t.IsEndTag() && t.AsEndTag().Name().Equals("noscript"))
     {
         tb.Pop();
         tb.Transition(HtmlTreeBuilderState.InHead);
     }
     else if (HtmlTreeBuilderState.IsWhitespace(t)
         || t.IsComment()
         || (t.IsStartTag() && StringUtil.In(t.AsStartTag().Name(), "basefont", "bgsound", "link", "meta", "noframes", "style")))
     {
         return tb.Process(t, HtmlTreeBuilderState.InHead);
     }
     else if (t.IsEndTag() && t.AsEndTag().Name().Equals("br"))
     {
         return this.AnythingElse(t, tb);
     }
     else if ((t.IsStartTag() && StringUtil.In(t.AsStartTag().Name(), "head", "noscript"))
         || t.IsEndTag())
     {
         tb.Error(this);
         return false;
     }
     else
     {
         return this.AnythingElse(t, tb);
     }
     return true;
 }
Exemple #5
0
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (HtmlTreeBuilderState.IsWhitespace(t))
     {
         return tb.Process(t, HtmlTreeBuilderState.InBody);
     }
     else if (t.IsComment())
     {
         tb.Insert(t.AsComment());
         // into html node
     }
     else if (t.IsDoctype())
     {
         tb.Error(this);
         return false;
     }
     else if (t.IsStartTag() && t.AsStartTag().Name().Equals("html"))
     {
         return tb.Process(t, HtmlTreeBuilderState.InBody);
     }
     else if (t.IsEndTag() && t.AsEndTag().Name().Equals("html"))
     {
         if (tb.IsFragmentParsing())
         {
             tb.Error(this);
             return false;
         }
         else
         {
             tb.Transition(HtmlTreeBuilderState.AfterAfterBody);
         }
     }
     else if (t.IsEOF())
     {
         // chillax! we're done
     }
     else
     {
         tb.Error(this);
         tb.Transition(HtmlTreeBuilderState.InBody);
         return tb.Process(t);
     }
     return true;
 }
Exemple #6
0
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (HtmlTreeBuilderState.IsWhitespace(t))
     {
         tb.Insert(t.AsCharacter());
     }
     else if (t.IsComment())
     {
         tb.Insert(t.AsComment());
     }
     else if (t.IsDoctype())
     {
         tb.Error(this);
         return false;
     }
     else if (t.IsStartTag())
     {
         Token.StartTag start = t.AsStartTag();
         string name = start.Name();
         if (name.Equals("html"))
         {
             return tb.Process(start, HtmlTreeBuilderState.InBody);
         }
         else if (name.Equals("frameset"))
         {
             tb.Insert(start);
         }
         else if (name.Equals("frame"))
         {
             tb.InsertEmpty(start);
         }
         else if (name.Equals("noframes"))
         {
             return tb.Process(start, HtmlTreeBuilderState.InHead);
         }
         else
         {
             tb.Error(this);
             return false;
         }
     }
     else if (t.IsEndTag() && t.AsEndTag().Name().Equals("frameset"))
     {
         if (tb.CurrentElement().NodeName.Equals("html"))
         {
             // frag
             tb.Error(this);
             return false;
         }
         else
         {
             tb.Pop();
             if (!tb.IsFragmentParsing() && !tb.CurrentElement().NodeName.Equals("frameset"))
             {
                 tb.Transition(HtmlTreeBuilderState.AfterFrameset);
             }
         }
     }
     else if (t.IsEOF())
     {
         if (!tb.CurrentElement().NodeName.Equals("html"))
         {
             tb.Error(this);
             return true;
         }
     }
     else
     {
         tb.Error(this);
         return false;
     }
     return true;
 }
Exemple #7
0
 internal override bool Process(Token t, HtmlTreeBuilder 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(HtmlTreeBuilderState.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(HtmlTreeBuilderState.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;
             }
             this.CloseCell(tb);
             return tb.Process(t);
         }
         else
         {
             return this.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;
         }
         this.CloseCell(tb);
         return tb.Process(t);
     }
     else
     {
         return this.AnythingElse(t, tb);
     }
     return true;
 }
Exemple #8
0
 internal override bool Process(Token t, HtmlTreeBuilder 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, HtmlTreeBuilderState.InSelect);
     }
 }
Exemple #9
0
 internal 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(HtmlTreeBuilderState.InCell);
             tb.InsertMarkerToFormattingElements();
         }
         else if (StringUtil.In(name, "caption", "col", "colgroup", "tbody", "tfoot", "thead", "tr"))
         {
             return this.HandleMissingTr(t, tb);
         }
         else
         {
             return this.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(HtmlTreeBuilderState.InTableBody);
         }
         else if (name.Equals("table"))
         {
             return this.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 this.AnythingElse(t, tb);
         }
     }
     else
     {
         return this.AnythingElse(t, tb);
     }
     return true;
 }
Exemple #10
0
 internal 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(HtmlTreeBuilderState.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, HtmlTreeBuilderState.InBody);
     }
     return true;
 }
Exemple #11
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);
 }
Exemple #12
0
 // in script, style etc. normally treated as data tags
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (t.IsCharacter())
     {
         tb.Insert(t.AsCharacter());
     }
     else if (t.IsEOF())
     {
         tb.Error(this);
         // if current node is script: already started
         tb.Pop();
         tb.Transition(tb.OriginalState());
         return tb.Process(t);
     }
     else if (t.IsEndTag())
     {
         // if: An end tag whose tag name is "script" -- scripting nesting level, if evaluating scripts
         tb.Pop();
         tb.Transition(tb.OriginalState());
     }
     return true;
 }
Exemple #13
0
 internal override bool Process(Token t, HtmlTreeBuilder tb)
 {
     if (HtmlTreeBuilderState.IsWhitespace(t))
     {
         return true;
     }
     else if (t.IsComment())
     {
         tb.Insert(t.AsComment());
     }
     else if (t.IsDoctype())
     {
         tb.Error(this);
         return false;
     }
     else if (t.IsStartTag() && t.AsStartTag().Name().Equals("html"))
     {
         return HtmlTreeBuilderState.InBody.Process(t, tb);
         // does not transition
     }
     else if (t.IsStartTag() && t.AsStartTag().Name().Equals("head"))
     {
         Element head = tb.Insert(t.AsStartTag());
         tb.SetHeadElement(head);
         tb.Transition(HtmlTreeBuilderState.InHead);
     }
     else if (t.IsEndTag() && (StringUtil.In(t.AsEndTag().Name(), "head", "body", "html", "br")))
     {
         tb.Process(new Token.StartTag("head"));
         return tb.Process(t);
     }
     else if (t.IsEndTag())
     {
         tb.Error(this);
         return false;
     }
     else
     {
         tb.Process(new Token.StartTag("head"));
         return tb.Process(t);
     }
     return true;
 }