Пример #1
0
        private void Process(HtmlTokenId tokenId)
        {
            token = parser.Token;

            switch (tokenId)
            {
            case HtmlTokenId.Tag:

                if (token.TagIndex <= HtmlTagIndex.Unknown)
                {
                    break;
                }

                var tagDef = GetTagDefinition(token.TagIndex);

                if (normalizedInput)
                {
                    if (!token.IsEndTag)
                    {
                        if (token.IsTagBegin)
                        {
                            PushElement(tagDef);
                        }

                        ProcessStartTagAttributes(tagDef);
                    }
                    else
                    {
                        if (token.IsTagBegin)
                        {
                            PopElement(tagDef);
                        }
                    }
                }
                else
                {
                    if (!token.IsEndTag)
                    {
                        if (token.IsTagBegin)
                        {
                            LFillTagB(tagDef);
                            PushElement(tagDef);
                            RFillTagB(tagDef);
                        }

                        ProcessStartTagAttributes(tagDef);
                    }
                    else
                    {
                        if (token.IsTagBegin)
                        {
                            LFillTagE(tagDef);
                            PopElement(tagDef);
                            RFillTagE(tagDef);
                        }
                    }
                }
                break;



            case HtmlTokenId.Text:

                if (!insideComment)
                {
                    if (insideAnchor && urlCompareSink.IsActive)
                    {
                        token.Text.WriteTo(urlCompareSink);
                    }

                    if (insidePre)
                    {
                        ProcessPreformatedText();
                    }
                    else if (normalizedInput)
                    {
                        ProcessText();
                    }
                    else
                    {
                        NormalizeProcessText();
                    }
                }
                break;



            case HtmlTokenId.OverlappedClose:
            case HtmlTokenId.OverlappedReopen:

                break;



            case HtmlTokenId.Restart:

                break;



            case HtmlTokenId.EncodingChange:

                if (output.OutputCodePageSameAsInput)
                {
                    var codePage = token.Argument;

                        #if DEBUG
                    Encoding newOutputEncoding;

                    InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding));
                        #endif



                    output.OutputEncoding = Charset.GetEncoding(codePage);
                }

                break;



            case HtmlTokenId.EndOfFile:

                if (lineStarted)
                {
                    output.OutputNewLine();
                    lineStarted = false;
                }

                if (!convertFragment)
                {
                    if (injection != null && injection.HaveHead)
                    {
                        if (wideGap)
                        {
                            output.OutputNewLine();
                            wideGap = false;
                        }

                        injection.Inject(false, output);
                    }

                    output.CloseDocument();
                    output.Flush();
                }

                endOfFile = true;
                break;
            }
        }