Ejemplo n.º 1
0
 public override bool Process(Token token)
 {
     // start tag, end tag, doctype, comment, character, eof
     switch (token.Type)
     {
         case Token.TokenType.StartTag:
             Insert(token.AsStartTag());
             break;
         case Token.TokenType.EndTag:
             PopStackToClose(token.AsEndTag());
             break;
         case Token.TokenType.Comment:
             Insert(token.AsComment());
             break;
         case Token.TokenType.Character:
             Insert(token.AsCharacter());
             break;
         case Token.TokenType.Doctype:
             Insert(token.AsDoctype());
             break;
         case Token.TokenType.EOF: // could put some normalisation here if desired
             break;
         default:
             throw new Exception("Unexpected token type: " + token.Type);
     }
     return true;
 }
Ejemplo n.º 2
0
        public override bool Process(Token token)
        {
            // start tag, end tag, doctype, comment, character, eof
            switch (token.Type)
            {
            case Token.TokenType.StartTag:
                Insert(token.AsStartTag());
                break;

            case Token.TokenType.EndTag:
                PopStackToClose(token.AsEndTag());
                break;

            case Token.TokenType.Comment:
                Insert(token.AsComment());
                break;

            case Token.TokenType.Character:
                Insert(token.AsCharacter());
                break;

            case Token.TokenType.Doctype:
                Insert(token.AsDoctype());
                break;

            case Token.TokenType.EOF:     // could put some normalisation here if desired
                break;

            default:
                throw new Exception("Unexpected token type: " + token.Type);
            }
            return(true);
        }
Ejemplo n.º 3
0
            public override bool Process(Token t, TreeBuilder tb)
            {
                if (IsWhitespace(t))
                {
                    return true; // ignore whitespace
                }
                else if (t.IsComment())
                {
                    tb.Insert(t.AsComment());
                }
                else if (t.IsDoctype())
                {
                    // todo: parse error check on expected doctypes
                    // todo: quirk state check on doctype ids
                    Token.Doctype d = t.AsDoctype();
                    DocumentType doctype = new DocumentType(d.Name.ToString(), d.PublicIdentifier.ToString(), d.SystemIdentifier.ToString(), tb.BaseUri.ToString());
                    tb.Document.AppendChild(doctype);

                    if (d.ForceQuirks)
                    {
                        tb.Document.QuirksMode(Document.QuirksModeEnum.Quirks);
                    }
                    tb.Transition(BeforeHtml);
                }
                else
                {
                    // todo: check not iframe srcdoc
                    tb.Transition(BeforeHtml);
                    return tb.Process(t); // re-process token
                }
                return true;
            }