An HTML DOCTYPE token.
An HTML DOCTYPE token.
Inheritance: HtmlToken
示例#1
0
 HtmlToken EmitDocType()
 {
     var token = doctype;
     data.Length = 0;
     doctype = null;
     return token;
 }
示例#2
0
        // 8.2.4.45 Markup declaration open state
        HtmlToken ReadMarkupDeclarationOpen()
        {
            int count = 0, nc;
            char c = '\0';

            while (count < 2) {
                if ((nc = Peek ()) == -1) {
                    TokenizerState = HtmlTokenizerState.EndOfFile;
                    return EmitDataToken (false);
                }

                if ((c = (char) nc) != '-')
                    break;

                // Note: we save the data in case we hit a parse error and have to emit a data token
                data.Append (c);
                Read ();
                count++;
            }

            if (count == 2) {
                TokenizerState = HtmlTokenizerState.CommentStart;
                name.Length = 0;
                return null;
            }

            if (count == 1) {
                // parse error
                TokenizerState = HtmlTokenizerState.BogusComment;
                return null;
            }

            if (c == 'D' || c == 'd') {
                // Note: we save the data in case we hit a parse error and have to emit a data token
                data.Append (c);
                name.Append (c);
                count = 1;
                Read ();

                while (count < 7) {
                    if ((nc = Read ()) == -1) {
                        TokenizerState = HtmlTokenizerState.EndOfFile;
                        return EmitDataToken (false);
                    }

                    if (ToLower ((c = (char) nc)) != DocType[count])
                        break;

                    // Note: we save the data in case we hit a parse error and have to emit a data token
                    data.Append (c);
                    name.Append (c);
                    count++;
                }

                if (count == 7) {
                    doctype = CreateDocTypeToken (name.ToString ());
                    TokenizerState = HtmlTokenizerState.DocType;
                    name.Length = 0;
                    return null;
                }

                name.Length = 0;
            } else if (c == '[') {
                // Note: we save the data in case we hit a parse error and have to emit a data token
                data.Append (c);
                count = 1;
                Read ();

                while (count < 7) {
                    if ((nc = Read ()) == -1) {
                        TokenizerState = HtmlTokenizerState.EndOfFile;
                        return EmitDataToken (false);
                    }

                    c = (char) nc;

                    // Note: we save the data in case we hit a parse error and have to emit a data token
                    data.Append (c);

                    if (c != CData[count])
                        break;

                    count++;
                }

                if (count == 7) {
                    TokenizerState = HtmlTokenizerState.CDataSection;
                    data.Length = 0;
                    return null;
                }
            }

            // parse error
            TokenizerState = HtmlTokenizerState.BogusComment;

            return null;
        }