Beispiel #1
0
 public void EmitToken(BaseToken token)
 {
     StartTagToken startTagToken = token as StartTagToken;
     if (startTagToken != null)
     {
         m_LastEmittedStartTag = startTagToken;
     }
     TreeConstruction.Instance.ProcessToken(this, token);
 }
        public override BaseInsertionModeState ProcessToken(HtmlTokenizer tokenizer, ITokenQueue queue, BaseToken token, IDocument doc)
        {
            if (IsWhitespace(token))
            {
                return this;
            }

            CommentToken commentToken = token as CommentToken;
            if (commentToken != null)
            {
                InsertComment(commentToken, doc);
                return this;
            }

            if (token is DocTypeToken)
            {
                ReportParseError();
                return this;
            }

            StartTagToken startTagToken = token as StartTagToken;
            if (startTagToken != null)
            {
                if (startTagToken.TagName == "html")
                {
                    //TODO - Process the token using the rules for the "in body" insertion mode.
                }
                else if (startTagToken.TagName == "head")
                {
                    ((Document)doc).head = (IHTMLHeadElement)base.InsertHtmlElement(startTagToken, doc);
                    return InHeadInsertionModeState.Instance;
                }
            }

            EndTagToken endTagToken = token as EndTagToken;
            if ((endTagToken == null) ||
                (endTagToken != null &&
                 endTagToken.TagName != "head" &&
                 endTagToken.TagName != "body" &&
                 endTagToken.TagName != "html" &&
                 endTagToken.TagName != "br"))
            {
                ReportParseError();
                return this;
            }

            //Insert an HTML element for a "head" start tag token with no attributes.
            //Set the head element pointer to the newly created head element.
            StartTagToken dummyToken = new StartTagToken(){ TagName = "head" };
            ((Document)doc).head = (IHTMLHeadElement)InsertHtmlElement(dummyToken, doc);

            //Switch the insertion mode to "in head".
            //Reprocess the current token.
            queue.EnqueueTokenForReprocessing(token);
            return InHeadInsertionModeState.Instance;
        }
Beispiel #3
0
        public override BaseState Process(HtmlTokenizer tokenizer, StreamReader reader)
        {
            char c = (char)Read(reader);
            if (c == '!')
            {
                return MarkupDeclarationOpenState.Instance;
            }

            if (c == '/')
            {
                return EndTagOpenState.Instance;
            }

            if (base.IsUppercaseAsciiLetter(c))
            {
                StartTagToken token = new StartTagToken();
                token.TagName = Char.ToLower(c).ToString();
                TagNameState.Instance.Token = token;
                return TagNameState.Instance;
            }

            if (base.IsLowercaseAsciiLetter(c))
            {
                StartTagToken token = new StartTagToken();
                token.TagName = ((char)c).ToString();
                TagNameState.Instance.Token = token;
                return TagNameState.Instance;
            }

            if (c == '?')
            {
                ReportParseError();
                return BogusCommentState.Instance;
            }

            ReportParseError();
            tokenizer.EmitChar(c);
            DataState.Instance.LastConsumedCharacters.Enqueue(c);
            return DataState.Instance;
        }
        public override BaseInsertionModeState ProcessToken(HtmlTokenizer tokenizer, ITokenQueue queue, BaseToken token, IDocument doc)
        {
            if (IsWhitespace(token))
            {
                InsertCharacter((CharacterToken)token, doc);
                return this;
            }

            CommentToken commentToken = token as CommentToken;
            if (commentToken != null)
            {
                InsertComment(commentToken, doc);
                return this;
            }

            if (token is DocTypeToken)
            {
                ReportParseError();
                return this;
            }

            StartTagToken startTagToken = token as StartTagToken;
            if (startTagToken != null)
            {
                switch(startTagToken.TagName)
                {
                    case "html":
                        //TODO - Process the token using the rules for the "in body" insertion mode.
                        break;

                    case "body":
                        // TODO - Insert an HTML element for the token.
                        // TODO - Set the frameset-ok flag to "not ok".
                        return InBodyInsertionModeState.Instance;

                    case "frameset":
                        // TODO - Insert an HTML element for the token.
                        return InFramesetInsertionModeState.Instance;

                    case "base":
                    case "basefont":
                    case "bgsound":
                    case "link":
                    case "meta":
                    case "noframes":
                    case "script":
                    case "style":
                    case "template":
                    case "title":
                        ReportParseError();
                        // TODO - Push the node pointed to by the head element pointer onto the stack of open elements.
                        // TODO - Process the token using the rules for the "in head" insertion mode.
                        // TODO - Remove the node pointed to by the head element pointer from the stack of open elements. (It might not be the current node at this point.)
                        // TODO - NOTE: The head element pointer cannot be null at this point.
                        break;

                    case "head":
                        ReportParseError();
                        return this;
                }
            }
            EndTagToken endTagToken = token as EndTagToken;
            if (endTagToken != null)
            {
                switch (endTagToken.TagName)
                {
                    case "template":
                        // TODO - Process the token using the rules for the "in head" insertion mode.
                        break;

                    case "body":
                    case "html":
                    case "br":
                        // TODO - Act as described in the "anything else" entry below.
                        break;

                    default:
                        ReportParseError();
                        return this;
                }
            }

            StartTagToken dummyToken = new StartTagToken(){ TagName = "body" };
            InsertHtmlElement(dummyToken, doc);

            queue.EnqueueTokenForReprocessing(token);
            return InBodyInsertionModeState.Instance;
        }