Пример #1
0
        public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
        {
            if(token.IsStartTag("html")){
                tree.AppendToken<InBodyInsertionMode>(token);
                return;
            }

            if(token.IsStartTag("body")){
                tree.InsertElementForToken(token);
                tree.Parser.FramesetOK = false;
                tree.ChangeInsertionMode<InBodyInsertionMode>();
                return;
            }

            if(token.IsStartTag("frameset")){
                tree.InsertElementForToken(token);
                tree.ChangeInsertionMode<InFramesetInsertionMode>();
                return;
            }

            if(token.IsStartTag("base", "basefont", "bgsound", "link", "meta", "noframes", "script", "style", "title")){
                OnMessageRaised(new UnexpectedInHeadElementError(token.Name));
                tree.PutToStack(tree.HeadElementPointer);
                tree.AppendToken<InHeadInsertionMode>(token);
                tree.PopFromStack();
                return;
            }
            if(token.IsStartTag("head")){
                OnMessageRaised(new MultipleHeadElementError());
                return;
            }

            AppendAnythingElse(tree, token);
        }
Пример #2
0
 public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
 {
     switch(token.Name){
     case "tr":
         tree.StackOfOpenElements.ClearBackToTableBody();
         tree.InsertElementForToken(token);
         tree.ChangeInsertionMode<InRowInsertionMode>();
         return;
     case "th":
     case "td":
         OnMessageRaised(new CellWithoutTableRowError(token.Name));
         AppendStartTagToken(tree, new FakeStartTagToken(){Name = "tr"});
         tree.ReprocessFlag = true;
         return;
     case "caption":
     case "col":
     case "colgroup":
     case "tbody":
     case "tfoot":
     case "thead":
         tree.StackOfOpenElements.ClearBackToTableBody();
         AppendEndTagToken(tree, new FakeEndTagToken(){Name = tree.CurrentNode.Name});
         tree.ReprocessFlag = true;
         return;
     }
     AppendAnythingElse(tree, token);
 }
Пример #3
0
 public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
 {
     switch(token.Name){
     case "caption":
         tree.StackOfOpenElements.ClearBackToTable();
         tree.ListOfActiveFormatElements.InsertMarker();
         tree.InsertElementForToken(token);
         tree.ChangeInsertionMode<InCaptionInsertionMode>();
         return;
     case "colgroup":
         tree.StackOfOpenElements.ClearBackToTable();
         tree.InsertElementForToken(token);
         tree.ChangeInsertionMode<InColumnGroupInsertionMode>();
         return;
     case "col":
         AppendStartTagToken(tree, new FakeStartTagToken(){Name = "colgroup"});
         tree.ReprocessFlag = true;
         return;
     case "tbody":
     case "tfoot":
     case "thead":
         tree.StackOfOpenElements.ClearBackToTable();
         tree.InsertElementForToken(token);
         tree.ChangeInsertionMode<InTableBodyInsertionMode>();
         return;
     case "td":
     case "th":
     case "tr":
         AppendStartTagToken(tree, new FakeStartTagToken(){Name = "tbody"});
         tree.ReprocessFlag = true;
         return;
     case "table":
         OnMessageRaised(new DoubleTableError());
         AppendEndTagToken(tree, new FakeEndTagToken(){Name = "table"});
         // このパーサーは fragment case を実装しない
         // then, if that token wasn't ignored, reprocess the current token.
         // Note: The fake end tag token here can only be ignored in the fragment case.
         tree.ReprocessFlag = true;
         return;
     case "input":
         if(!token.IsHiddenType()){
             AppendAnythingElse(tree, token);
             return;
         }
         OnMessageRaised(new HiddenInputInTableError());
         tree.InsertElementForToken(token);
         tree.PopFromStack();
         return;
     case "form":
         OnMessageRaised(new FormInTableError());
         if(tree.FormElementPointer != null) return;
         XmlElement form = tree.InsertElementForToken(token);
         tree.FormElementPointer = form;
         tree.PopFromStack();
         return;
     }
     AppendAnythingElse(tree, token);
 }
Пример #4
0
 public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
 {
     switch(token.Name){
     case "html":
         tree.AppendToken<InBodyInsertionMode>(token);
         return;
     }
     AppendAnythingElse(tree, token);
 }
Пример #5
0
 public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
 {
     if(token.IsStartTag("html")){
         XmlElement htmlElement = tree.CreateElementForToken((TagToken)token);
         tree.AppendChild(htmlElement);
         tree.PutToStack(htmlElement);
         tree.ChangeInsertionMode<BeforeHeadInsertionMode>();
         return;
     }
     AppendAnythingElse(tree, token);
 }
Пример #6
0
 public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
 {
     switch(token.Name){
     case "html":
         tree.AppendToken<InBodyInsertionMode>(token);
         return;
     case "col":
         tree.InsertElementForToken(token);
         tree.PopFromStack();
         tree.AcknowledgeSelfClosingFlag(token);
         return;
     }
     AppendAnythingElse(tree, token);
 }
Пример #7
0
        public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
        {
            if(token.IsStartTag("html")){
                tree.AppendToken<InBodyInsertionMode>(token);
                return;
            }

            if(token.IsStartTag("head")){
                XmlElement headElement = tree.InsertElementForToken((StartTagToken)token);
                tree.HeadElementPointer = headElement;
                tree.ChangeInsertionMode<InHeadInsertionMode>();
                return;
            }
            AppendAnythingElse(tree, token);
        }
Пример #8
0
        public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
        {
            switch(token.Name){
            case "html":
                tree.AppendToken<InBodyInsertionMode>(token);
                return;

            case "option":
                if(tree.StackOfOpenElements.IsCurrentNameMatch("option")){
                    AppendEndTagToken(tree, new FakeEndTagToken(){Name = "option"});
                }
                tree.InsertElementForToken(token);
                return;

            case "optgroup":
                if(tree.StackOfOpenElements.IsCurrentNameMatch("option")){
                    AppendEndTagToken(tree, new FakeEndTagToken(){Name = "option"});
                }
                if(tree.StackOfOpenElements.IsCurrentNameMatch("optgroup")){
                    AppendEndTagToken(tree, new FakeEndTagToken(){Name = "optgroup"});
                }
                tree.InsertElementForToken(token);
                return;

            case "select":
                if(!tree.StackOfOpenElements.HaveElementInSelectScope(token.Name)){
                    OnMessageRaised(new NestedSelectElementError());
                    AppendEndTagToken(tree, new FakeEndTagToken(){Name = "select"});
                    return;
                }
                return;

            case "input":
            case "keygen":
            case "textarea":
                OnMessageRaised(new UnexpectedStartTagInSelectError(token.Name));
                AppendEndTagToken(tree, new FakeEndTagToken(){Name = "select"});
                tree.ReprocessFlag = true;
                return;

            case "script":
                tree.AppendToken<InHeadInsertionMode>(token);
                return;

            }
            AppendAnythingElse(tree, token);
        }
Пример #9
0
        public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
        {
            if(token.IsStartTag("html")){
                tree.AppendToken<InBodyInsertionMode>(token);
                return;
            }

            if(token.IsStartTag("basefont", "bgsound", "link", "meta", "noframes", "style")){
                tree.AppendToken<InHeadInsertionMode>(token);
                return;
            }
            if(token.IsStartTag("head", "noscript")){
                OnMessageRaised(new UnexpectedStartTagInHeadNoscriptError(token.Name));
                return;
            }
            AppendAnythingElse(tree, token);
        }
Пример #10
0
 public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
 {
     switch(token.Name){
     case "caption":
     case "col":
     case "colgroup":
     case "tbody":
     case "td":
     case "tfoot":
     case "th":
     case "thead":
     case "tr":
         CloseTheCell(tree);
         tree.ReprocessFlag = true;
         return;
     }
     AppendAnythingElse(tree, token);
 }
Пример #11
0
 public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
 {
     switch(token.Name){
     case "caption":
     case "table":
     case "tbody":
     case "tfoot":
     case "thead":
     case "tr":
     case "td":
     case "th":
         OnMessageRaised(new UnexpectedStartTagInSelectInTableError(token.Name));
         AppendEndTagToken(tree, new FakeEndTagToken(){Name = "select"});
         tree.ReprocessFlag = true;
         return;
     }
     AppendAnythingElse(tree, token);
 }
Пример #12
0
        public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
        {
            switch(token.Name){
            case "th":
            case "td":
                tree.StackOfOpenElements.ClearBackToTableRow();
                tree.InsertElementForToken(token);
                tree.ChangeInsertionMode<InCellInsertionMode>();
                tree.ListOfActiveFormatElements.InsertMarker();
                return;

            case "caption":
            case "col":
            case "colgroup":
            case "tbody":
            case "tfoot":
            case "thead":
            case "tr":
                AppendEndTagToken(tree, new FakeEndTagToken(){Name = "tr"});
                tree.ReprocessFlag = true;
                return;
            }
            AppendAnythingElse(tree, token);
        }
Пример #13
0
 public virtual void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
 {
     AppendAnythingElse(tree, token);
 }
Пример #14
0
        public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
        {
            if(token.IsStartTag("html")){
                OnMessageRaised(new MultipleHtmlElementError());
                XmlElement topElement = tree.StackOfOpenElements[0];
                tree.MergeAttribute(topElement, token);
                return;
            }

            if(token.IsStartTag("base", "basefont", "bgsound", "command", "link", "meta", "noframes", "script", "style", "title")){
                tree.AppendToken<InHeadInsertionMode>(token);
                return;
            }

            if(token.IsStartTag("body")){
                OnMessageRaised(new MultipleBodyElementError());
                XmlElement bodyElement = tree.StackOfOpenElements[1];
                if(bodyElement == null || bodyElement.Name != "body") return;
                tree.Parser.FramesetOK = false;
                tree.MergeAttribute(bodyElement, token);
                return;
            }

            if(token.IsStartTag("frameset")){
                OnMessageRaised(new UnexpectedFramesetElementError());
                XmlElement bodyElement = tree.StackOfOpenElements[1];
                if(bodyElement == null || bodyElement.Name != "body") return;
                if(tree.Parser.FramesetOK == false) return;

                bodyElement.ParentNode.RemoveChild(bodyElement);
                while(tree.StackOfOpenElements.Count > 1) tree.StackOfOpenElements.Pop();
                tree.InsertElementForToken(token);
                tree.ChangeInsertionMode<InFramesetInsertionMode>();
                return;
            }

            if(token.IsStartTag("address", "article", "aside", "blockquote", "center", "details", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section", "summary", "ul")){
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                tree.InsertElementForToken(token);
                return;
            }

            if(token.IsStartTag(myHeadingElements)){
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                if(tree.StackOfOpenElements.IsCurrentNameMatch(myHeadingElements)){
                    OnMessageRaised(new NestedHeadingElementError(tree.CurrentNode.Name, token.Name));
                    tree.StackOfOpenElements.Pop();
                }
                tree.InsertElementForToken(token);
                return;
            }

            if(token.IsStartTag("pre", "listing")){
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                tree.InsertElementForToken(token);
                tree.Parser.FramesetOK = false;
                tree.IgnoreNextLineFeed = true;
                return;
            }

            if(token.IsStartTag("form")){
                if(tree.FormElementPointer != null){
                    OnMessageRaised(new NestedFormElementError());
                    return;
                }
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                XmlElement form = tree.InsertElementForToken(token);
                tree.FormElementPointer = form;
                return;
            }

            if(token.IsStartTag("li")){
                tree.Parser.FramesetOK = false;
                foreach(XmlElement e in tree.StackOfOpenElements){
                    if(StackOfElements.IsNameMatch(e, "li")){
                        EndTagHadBeSeen(tree, "li");
                        break;
                    }
                    if(StackOfElements.IsSpecialElement(e)){
                        if(!StackOfElements.IsNameMatch(e, "address", "div", "p")){
                            break;
                        }
                    }
                }
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                tree.InsertElementForToken(token);
                return;
            }

            if(token.IsStartTag("dd", "dt")){
                tree.Parser.FramesetOK = false;
                foreach(XmlElement e in tree.StackOfOpenElements){
                    if(StackOfElements.IsNameMatch(e, "dd", "dt")){
                        EndTagHadBeSeen(tree, token.Name);
                        break;
                    }
                    if(StackOfElements.IsSpecialElement(e)){
                        if(!StackOfElements.IsNameMatch(e, "address", "div", "p")){
                            break;
                        }
                    }
                }
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                tree.InsertElementForToken(token);
                return;
            }

            if(token.IsStartTag("plaintext")){
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                tree.InsertElementForToken(token);
                tree.Parser.ChangeTokenState<PLAINTEXTState>();
                return;
            }

            if(token.IsStartTag("button")){
                if(tree.StackOfOpenElements.HaveElementInScope("button")){
                    OnMessageRaised(new NestedButtonElementError());
                    EndTagHadBeSeen(tree, "button");
                    tree.ReprocessFlag = true;
                    return;
                }
                Reconstruct(tree, token);
                tree.InsertElementForToken(token);
                tree.Parser.FramesetOK = false;
                return;
            }

            if(token.IsStartTag("a")){
                var list = tree.ListOfActiveFormatElements;
                var stack = tree.StackOfOpenElements;
                int index = list.GetAfterMarkerIndexByName("a");
                if(index >=0){
                    XmlElement aElement = list.GetAfterMarkerByAfterIndex(index);
                    OnMessageRaised(new NestedAnchorElementError());
                    EndTagHadBeSeen(tree, "a");
                    stack.Remove(aElement);
                    list.Remove(aElement);
                }
                Reconstruct(tree, token);
                XmlElement e = tree.InsertElementForToken(token);
                tree.ListOfActiveFormatElements.Push(e, token);
                return;
            }

            if(token.IsStartTag("b", "big", "code", "em", "font", "i", "s", "small", "strike", "strong", "tt", "u")){
                Reconstruct(tree, token);
                XmlElement e = tree.InsertElementForToken(token);
                tree.ListOfActiveFormatElements.Push(e, token);
                return;
            }

            if(token.IsStartTag("nobr")){
                Reconstruct(tree, token);
                if(!tree.StackOfOpenElements.HaveElementInScope(token.Name)){
                    OnMessageRaised(new NestedNobrElementError());
                    FormatEndTagHadBeSeen(tree, token, "nobr");
                    Reconstruct(tree, token);
                    return;
                }
                XmlElement e = tree.InsertElementForToken(token);
                tree.ListOfActiveFormatElements.Push(e, token);
                return;
            }

            if(token.IsStartTag("applet", "marquee", "object")){
                Reconstruct(tree, token);
                tree.InsertElementForToken(token);
                tree.Parser.FramesetOK = false;
                tree.ListOfActiveFormatElements.InsertMarker();
                return;
            }

            if(token.IsStartTag("table")){
                if(tree.Document.DocumentMode == DocumentMode.Quirks && tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                tree.InsertElementForToken(token);
                tree.Parser.FramesetOK = false;
                tree.ChangeInsertionMode<InTableInsertionMode>();
                return;
            }

            if(token.IsStartTag("area", "br", "embed", "img", "keygen", "wbr")){
                Reconstruct(tree, token);
                tree.InsertElementForToken(token);
                tree.PopFromStack();
                tree.AcknowledgeSelfClosingFlag(token);
                tree.Parser.FramesetOK = false;
                return;
            }

            if(token.IsStartTag("input")){
                Reconstruct(tree, token);
                tree.InsertElementForToken(token);
                tree.PopFromStack();
                tree.AcknowledgeSelfClosingFlag(token);
                if(!token.IsHiddenType()){
                    tree.Parser.FramesetOK = false;
                }
                return;
            }

            if(token.IsStartTag("param", "source", "track")){
                tree.InsertElementForToken(token);
                tree.AcknowledgeSelfClosingFlag(token);
                tree.PopFromStack();
                return;
            }

            if(token.IsStartTag("hr")){
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                tree.InsertElementForToken(token);
                tree.AcknowledgeSelfClosingFlag(token);
                tree.PopFromStack();
                return;
            }

            if(token.IsStartTag("image")){
                OnMessageRaised(new ImageElementError());
                token.Name = "img";
                tree.ReprocessFlag = true;
                return;
            }

            if(token.IsStartTag("isindex")){
                OnMessageRaised(new IsindexElementError());
                XmlElement node = tree.FormElementPointer;
                if(node != null) return;
                tree.AcknowledgeSelfClosingFlag(token);

                StartTagHadBeSeen(tree, "form");
                XmlElement form = (XmlElement)tree.CurrentNode;
                string actionAttrValue = token.GetAttributeValue("action");
                if(actionAttrValue != null) form.SetAttribute("action", actionAttrValue);
                StartTagHadBeSeen(tree, "hr");
                StartTagHadBeSeen(tree, "label");
                string promptAttrValue = token.GetAttributeValue("prompt");
                if(promptAttrValue == null){
                    tree.InsertText("This is a searchable index. Enter search keywords:");
                } else {
                    tree.InsertText(promptAttrValue);

                }
                StartTagHadBeSeen(tree, "input");
                XmlElement input = (XmlElement)tree.CurrentNode["input"];
                input.SetAttribute("name", "isindex");
                foreach(AttributeToken at in token.Attributes){
                    if(at.Name == "name" || at.Name == "action" || at.Name == "prompt") continue;
                    input.SetAttribute(at.Name, at.Value);
                }
                EndTagHadBeSeen(tree, "label");
                StartTagHadBeSeen(tree, "hr");
                EndTagHadBeSeen(tree, "form");
                return;
            }

            if(token.IsStartTag("textarea")){
                tree.InsertElementForToken(token);
                tree.IgnoreNextLineFeed = true;
                tree.Parser.ChangeTokenState<RCDATAState>();
                tree.OriginalInsertionMode = tree.CurrentInsertionMode;
                tree.Parser.FramesetOK = false;
                tree.ChangeInsertionMode<TextInsertionMode>();
                return;
            }

            if(token.IsStartTag("xmp")){
                if(tree.StackOfOpenElements.HaveElementInButtonScope("p")){
                    EndTagPHadBeSeen(tree, token);
                }
                Reconstruct(tree, token);
                tree.Parser.FramesetOK = false;
                GenericRawtextElementParsingAlgorithm(tree, token);
                return;
            }

            if(token.IsStartTag("iframe")){
                tree.Parser.FramesetOK = false;
                GenericRawtextElementParsingAlgorithm(tree, token);
                return;
            }

            // start tag whose tag name is "noscript", if the scripting flag is enabled
            if(token.IsStartTag("noembed")){
                GenericRawtextElementParsingAlgorithm(tree, token);
                return;
            }

            if(token.IsStartTag("select")){
                Reconstruct(tree, token);
                tree.InsertElementForToken(token);
                tree.Parser.FramesetOK = false;
                if(tree.CurrentInsertionMode is TableRelatedInsertionMode){
                    tree.ChangeInsertionMode<InSelectInTableInsertionMode>();
                } else {
                    tree.ChangeInsertionMode<InSelectInsertionMode>();
                }
                return;
            }

            if(token.IsStartTag("optgroup", "option")){
                if(tree.CurrentNode.Name == "option") EndTagHadBeSeen(tree, "option");
                Reconstruct(tree, token);
                tree.InsertElementForToken(token);
                return;
            }

            if(token.IsStartTag("rp", "rt")){
                if(tree.StackOfOpenElements.HaveElementInScope("ruby")){
                    GenerateImpliedEndTags(tree, token);
                    if(!tree.StackOfOpenElements.IsCurrentNameMatch("ruby")){
                        OnMessageRaised(new DirectParentRequiredError(token.Name, "ruby", tree.CurrentNode.Name));
                        tree.StackOfOpenElements.PopUntilSameTagName("ruby");
                    }
                }
                tree.InsertElementForToken(token);
                return;
            }

            if(token.IsStartTag("math")){
                Reconstruct(tree, token);
                token.AdjustMathMLAttributes();
                token.AdjustForeignAttributes();
                XmlElement result = tree.CreateElementForToken(token, Document.MathMLNamespace);
                tree.InsertElement(result);
                if(token.SelfClosing){
                    tree.AcknowledgeSelfClosingFlag(token);
                    tree.PopFromStack();
                }
                return;
            }

            if(token.IsStartTag("svg")){
                Reconstruct(tree, token);
                token.AdjustSVGAttributes();
                token.AdjustForeignAttributes();
                XmlElement result = tree.CreateElementForToken(token, Document.SVGNamespace);
                tree.InsertElement(result);
                if(token.SelfClosing){
                    tree.AcknowledgeSelfClosingFlag(token);
                    tree.PopFromStack();
                }
                return;
            }

            if(token.IsStartTag("caption", "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th", "thead", "tr")){
                OnMessageRaised(new ElementContextError(token.Name));
                return;
            }

            // Any Other Start Tags.
            Reconstruct(tree, token);
            tree.InsertElementForToken(token);
            return;
        }
Пример #15
0
        public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
        {
            if(token.IsStartTag("html")){
                tree.AppendToken<InBodyInsertionMode>(token);
                return;
            }

            if(token.IsStartTag("base", "basefont", "bgsound", "command", "link")){
                tree.InsertElementForToken(token);
                tree.PopFromStack();
                tree.AcknowledgeSelfClosingFlag(token);
                return;
            }

            if(token.IsStartTag("meta")){
                tree.InsertElementForToken(token);
                tree.PopFromStack();
                tree.AcknowledgeSelfClosingFlag(token);

                // charset判定
                string charsetValue = token.GetAttributeValue("charset");
                string httpEquivValue = token.GetAttributeValue("http-equiv");
                string contentValue = token.GetAttributeValue("content");
                string charsetName = null;

                if(charsetValue != null){
                    OnMessageRaised(new GenericVerbose(string.Format("meta要素のcharset属性が指定されています。: {0}", charsetValue)));
                    charsetName = charsetValue;
                    if(charsetName == ""){
                        OnMessageRaised(new EmptyCharsetWarning());
                        return;
                    }
                    OnMessageRaised(new GenericVerbose(string.Format("meta charset で文字符号化方式が指定されています。: {0}", charsetValue)));
                } else if(httpEquivValue != null && httpEquivValue.Equals("Content-Type", StringComparison.InvariantCultureIgnoreCase) && contentValue != null){
                    charsetName = EncodingSniffer.ExtractEncodingNameFromMetaElement(contentValue);

                    if(string.IsNullOrEmpty(charsetName)){
                        OnMessageRaised(new EmptyCharsetWarning());
                        return;
                    }
                    OnMessageRaised(new GenericVerbose(string.Format("meta http-equivで文字符号化方式が指定されています。: {0}({1})", contentValue, charsetName)));
                }

                if(charsetName == null) return;

                InputStream stream = tree.Parser.InputStream;
                if(stream.EncodingConfidence == EncodingConfidence.Irrelevant){
                    OnMessageRaised(new GenericVerbose(string.Format("metaで文字符号化方式が指定されていますが、文字符号化方式の判別が必要ないモードであるため、指定を無視します。")));
                    return;
                }

                OnMessageRaised(new GenericVerbose(string.Format("metaの属性値から文字符号化方式を決定します。")));
                Encoding enc = EncodingSniffer.GetEncodingByName(charsetName);
                if(enc == null){
                    OnMessageRaised(new UnknownCharsetWarning(charsetName));
                    return;
                }

                if(stream.EncodingConfidence == EncodingConfidence.Certain){
                    if(enc == stream.Encoding){
                        OnMessageRaised(new SameCharsetInformation(enc.EncodingName));
                    } else {
                        OnMessageRaised(new DifferentDoubleCharsetWarning(enc.EncodingName));
                    }
                    return;
                }

                // ToDo: Encodingを変更する
                stream.ChangeEncoding(enc);
                return;
            }

            if(token.IsStartTag("title")){
                GenericRCDATAElementParsingAlgorithm(tree, token);
                return;
            }

            // RedFaceParserは常にScriptingDisabled
            if(token.IsStartTag("noframes", "style")){
                GenericRawtextElementParsingAlgorithm(tree, token);
                return;
            }

            // RedFaceParserは常にScriptingDisabled
            if(token.IsStartTag("noscript")){
                tree.InsertElementForToken(token);
                tree.ChangeInsertionMode<InHeadNoscriptInsertionMode>();
                return;
            }

            if(token.IsStartTag("script")){
                XmlElement scriptElement = tree.CreateElementForToken(token);
                tree.AppendChild(scriptElement);
                tree.PutToStack(scriptElement);
                tree.Parser.ChangeTokenState<ScriptDataState>();
                tree.OriginalInsertionMode = tree.CurrentInsertionMode;
                tree.ChangeInsertionMode<TextInsertionMode>();
                return;
            }

            if(token.IsStartTag("head")){
                OnMessageRaised(new MultipleHeadElementError());
                return;
            }
            AppendAnythingElse(tree, token);
        }
Пример #16
0
        public override void AppendStartTagToken(TreeConstruction tree, StartTagToken token)
        {
            switch(token.Name){
            case "b":
            case "big":
            case "blockquote":
            case "body":
            case "br":
            case "center":
            case "code":
            case "dd":
            case "div":
            case "dl":
            case "dt":
            case "em":
            case "embed":
            case "h1":
            case "h2":
            case "h3":
            case "h4":
            case "h5":
            case "h6":
            case "head":
            case "hr":
            case "i":
            case "img":
            case "li":
            case "listing":
            case "menu":
            case "meta":
            case "nobr":
            case "ol":
            case "p":
            case "pre":
            case "ruby":
            case "s":
            case "small":
            case "span":
            case "strong":
            case "strike":
            case "sub":
            case "sup":
            case "table":
            case "tt":
            case "u":
            case "ul":
            case "var":
                AppendHtmlFormatStartTags(tree, token);
                return;

            case "font":
                if(token.HasAttribute("color") || token.HasAttribute("face") || token.HasAttribute("size")){
                    AppendHtmlFormatStartTags(tree, token);
                    return;
                } else {
                    break; // not return, treat as any other start tag
                }
            }

            // Any Other Start Tag
            XmlElement currentNode = tree.CurrentNode as XmlElement;
            if(ElementInfo.IsMathMLNameSpace(currentNode)){
                token.AdjustMathMLAttributes();
                token.AdjustForeignAttributes();
                tree.InsertForeignElementForToken(token, Document.MathMLNamespace);
            } else if(ElementInfo.IsSVGNameSpace(currentNode)){
                token.AdjustSVGElementName();
                token.AdjustSVGAttributes();
                token.AdjustForeignAttributes();
                tree.InsertForeignElementForToken(token, Document.SVGNamespace);
            }
            if(token.SelfClosing){
                tree.AcknowledgeSelfClosingFlag(token);
                tree.PopFromStack();
            }
            return;
        }