当前位置: 首页>>代码示例>>C#>>正文


C# HtmlToken类代码示例

本文整理汇总了C#中HtmlToken的典型用法代码示例。如果您正苦于以下问题:C# HtmlToken类的具体用法?C# HtmlToken怎么用?C# HtmlToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HtmlToken类属于命名空间,在下文中一共展示了HtmlToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InSelectInTable

        /// <summary>
        /// See 8.2.5.4.17 The "in select in table" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void InSelectInTable(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (TagNames.AllTableSelects.Contains(tagName))
                    {
                        RaiseErrorOccurred(HtmlParseError.IllegalElementInSelectDetected, token);
                        InSelectEndTagSelect();
                        Home(token);
                        return;
                    }

                    break;
                }
                case HtmlTokenType.EndTag:
                {
                    var tagName = token.Name;

                    if (TagNames.AllTableSelects.Contains(tagName))
                    {
                        RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);

                        if (IsInTableScope(tagName))
                        {
                            InSelectEndTagSelect();
                            Home(token);
                        }

                        return;
                    }

                    break;
                }
            }

            InSelect(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:45,代码来源:HtmlDomBuilder.cs

示例2: BeforeHead

        /// <summary>
        /// See 8.2.5.4.3 The "before head" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void BeforeHead(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    token.TrimStart();

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Html))
                    {
                        InBody(token);
                        return;
                    }
                    else if (tagName.Is(TagNames.Head))
                    {
                        AddElement(new HtmlHeadElement(_document), token.AsTag());
                        _currentMode = HtmlTreeMode.InHead;
                        return;
                    }

                    break;
                }
                case HtmlTokenType.EndTag:
                {
                    if (TagNames.AllBeforeHead.Contains(token.Name))
                        break;

                    RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
                    return;
                }
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
            }

            BeforeHead(HtmlTagToken.Open(TagNames.Head));
            InHead(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:58,代码来源:HtmlDomBuilder.cs

示例3: InHeadNoScript

        /// <summary>
        /// See 8.2.5.4.5 The "in head noscript" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void InHeadNoScript(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Comment:
                {
                    InHead(token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (TagNames.AllNoScript.Contains(tagName))
                        InHead(token);
                    else if (tagName.Is(TagNames.Html))
                        InBody(token);
                    else if (tagName.IsOneOf(TagNames.Head, TagNames.NoScript))
                        RaiseErrorOccurred(HtmlParseError.TagInappropriate, token);
                    else
                        break;

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.NoScript))
                    {
                        CloseCurrentNode();
                        _currentMode = HtmlTreeMode.InHead;
                        return;
                    }
                    else if (!tagName.Is(TagNames.Br))
                    {
                        RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
                        return;
                    }

                    break;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
            CloseCurrentNode();
            _currentMode = HtmlTreeMode.InHead;
            InHead(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:68,代码来源:HtmlDomBuilder.cs

示例4: CheckBodyOnClosing

 /// <summary>
 /// If there is a node in the stack of open elements that is not either
 /// a dd element, a dt element, an li element, a p element, a tbody
 /// element, a td element, a tfoot element, a th element, a thead
 /// element, a tr element, the body element, or the html element, then
 /// this is a parse error.
 /// </summary>
 void CheckBodyOnClosing(HtmlToken token)
 {
     for (var i = 0; i < _openElements.Count; i++)
     {
         if (!_openElements[i].Flags.HasFlag(NodeFlags.ImplicitelyClosed))
         {
             RaiseErrorOccurred(HtmlParseError.BodyClosedWrong, token);
             break;
         }
     }
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:18,代码来源:HtmlDomBuilder.cs

示例5: Initial

        /// <summary>
        /// See 8.2.5.4.1 The "initial" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void Initial(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Doctype:
                {
                    var doctype = (HtmlDoctypeToken)token;

                    if (!doctype.IsValid)
                        RaiseErrorOccurred(HtmlParseError.DoctypeInvalid, token);

                    _document.AddNode(new DocumentType(_document, doctype.Name ?? String.Empty)
                    {
                        SystemIdentifier = doctype.SystemIdentifier,
                        PublicIdentifier = doctype.PublicIdentifier
                    });

                    if (doctype.IsFullQuirks)
                        _document.QuirksMode = QuirksMode.On;
                    else if (doctype.IsLimitedQuirks)
                        _document.QuirksMode = QuirksMode.Limited;

                    _currentMode = HtmlTreeMode.BeforeHtml;
                    return;
                }
                case HtmlTokenType.Character:
                {
                    token.TrimStart();

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Comment:
                {
                    _document.AddComment(token);
                    return;
                }
            }

            if (_options.IsEmbedded == false)
            {
                RaiseErrorOccurred(HtmlParseError.DoctypeMissing, token);
                _document.QuirksMode = QuirksMode.On;
            }

            _currentMode = HtmlTreeMode.BeforeHtml;
            BeforeHtml(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:54,代码来源:HtmlDomBuilder.cs

示例6: InCaptionEndTagCaption

        /// <summary>
        /// Act as if an caption end tag has been found in the InCaption state.
        /// </summary>
        /// <param name="token">The actual tag token.</param>
        /// <returns>True if the token was not ignored, otherwise false.</returns>
        Boolean InCaptionEndTagCaption(HtmlToken token)
        {
            if (IsInTableScope(TagNames.Caption))
            {
                GenerateImpliedEndTags();

                if (!CurrentNode.LocalName.Is(TagNames.Caption))
                    RaiseErrorOccurred(HtmlParseError.TagDoesNotMatchCurrentNode, token);

                ClearStackBackTo(TagNames.Caption);
                CloseCurrentNode();
                _formattingElements.ClearFormatting();
                _currentMode = HtmlTreeMode.InTable;
                return true;
            }
            else
            {
                RaiseErrorOccurred(HtmlParseError.CaptionNotInScope, token);
                return false;
            }
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:26,代码来源:HtmlDomBuilder.cs

示例7: Foreign

        /// <summary>
        /// 8.2.5.5 The rules for parsing tokens in foreign content
        /// </summary>
        /// <param name="token">The token to examine.</param>
        void Foreign(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    AddCharacters(token.Data.Replace(Symbols.Null, Symbols.Replacement));

                    if (token.HasContent)
                        _frameset = false;

                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;
                    var tag = token.AsTag();

                    if (tagName.Is(TagNames.Font))
                    {
                        for (var i = 0; i != tag.Attributes.Count; i++)
                        {
                            if (tag.Attributes[i].Key.IsOneOf(AttributeNames.Color, AttributeNames.Face, AttributeNames.Size))
                            {
                                ForeignNormalTag(tag);
                                return;
                            }
                        }

                        ForeignSpecialTag(tag);
                    }
                    else if (TagNames.AllForeignExceptions.Contains(tagName))
                    {
                        ForeignNormalTag(tag);
                    }
                    else
                    {
                        ForeignSpecialTag(tag);
                    }

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    var tagName = token.Name;
                    var node = CurrentNode;
                    var script = node as HtmlScriptElement;

                    if (script != null)
                    {
                        HandleScript(script);
                        return;
                    }

                    if (!node.LocalName.Is(tagName))
                        RaiseErrorOccurred(HtmlParseError.TagClosingMismatch, token);

                    for (int i = _openElements.Count - 1; i > 0; i--)
                    {
                        if (node.LocalName.Isi(tagName))
                        {
                            _openElements.RemoveRange(i + 1, _openElements.Count - i - 1);
                            CloseCurrentNode();
                            break;
                        }

                        node = _openElements[i - 1];

                        if (node.Flags.HasFlag(NodeFlags.HtmlMember))
                        {
                            Home(token);
                            break;
                        }
                    }

                    return;
                }
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
            }
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:93,代码来源:HtmlDomBuilder.cs

示例8: AfterAfterFrameset

        /// <summary>
        /// See 8.2.5.4.23 The "after after frameset" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void AfterAfterFrameset(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Comment:
                {
                    _document.AddComment(token);
                    return;
                }
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    ReconstructFormatting();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Doctype:
                {
                    InBody(token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Html))
                        InBody(token);
                    else if (tagName.Is(TagNames.NoFrames))
                        InHead(token);
                    else
                        break;

                    return;
                }
                case HtmlTokenType.EndOfFile:
                {
                    End();
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:51,代码来源:HtmlDomBuilder.cs

示例9: TemplateStep

 /// <summary>
 /// Inserting something in the template.
 /// </summary>
 /// <param name="token">The token to insert.</param>
 /// <param name="mode">The mode to push.</param>
 void TemplateStep(HtmlToken token, HtmlTreeMode mode)
 {
     _templateModes.Pop();
     _templateModes.Push(mode);
     _currentMode = mode;
     Home(token);
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:12,代码来源:HtmlDomBuilder.cs

示例10: AfterFrameset

        /// <summary>
        /// See 8.2.5.4.21 The "after frameset" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void AfterFrameset(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Html))
                        InBody(token);
                    else if (tagName.Is(TagNames.NoFrames))
                        InHead(token);
                    else
                        break;

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    if (!token.Name.Is(TagNames.Html))
                        break;

                    _currentMode = HtmlTreeMode.AfterAfterFrameset;
                    return;
                }
                case HtmlTokenType.EndOfFile:
                {
                    End();
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:58,代码来源:HtmlDomBuilder.cs

示例11: AfterAfterBody

        /// <summary>
        /// See 8.2.5.4.22 The "after after body" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void AfterAfterBody(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    ReconstructFormatting();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.EndOfFile:
                {
                    End();
                    return;
                }
                case HtmlTokenType.Comment:
                {
                    _document.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    InBody(token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    if (!token.Name.Is(TagNames.Html))
                        break;

                    InBody(token);
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
            _currentMode = HtmlTreeMode.InBody;
            InBody(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:48,代码来源:HtmlDomBuilder.cs

示例12: InFrameset

        /// <summary>
        /// See 8.2.5.4.20 The "in frameset" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void InFrameset(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;

                    break;
                }
                case HtmlTokenType.Comment:
                {
                    CurrentNode.AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Html))
                        InBody(token);
                    else if (tagName.Is(TagNames.Frameset))
                        AddElement(new HtmlFrameSetElement(_document), token.AsTag());
                    else if (tagName.Is(TagNames.Frame))
                    {
                        AddElement(new HtmlFrameElement(_document), token.AsTag(), true);
                        CloseCurrentNode();
                    }
                    else if (tagName.Is(TagNames.NoFrames))
                        InHead(token);
                    else
                        break;

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    if (!token.Name.Is(TagNames.Frameset))
                        break;

                    if (CurrentNode != _openElements[0])
                    {
                        CloseCurrentNode();

                        if (!IsFragmentCase && !CurrentNode.LocalName.Is(TagNames.Frameset))
                            _currentMode = HtmlTreeMode.AfterFrameset;
                    }
                    else
                        RaiseErrorOccurred(HtmlParseError.CurrentNodeIsRoot, token);

                    return;
                }
                case HtmlTokenType.EndOfFile:
                {
                    if (CurrentNode != _document.DocumentElement)
                        RaiseErrorOccurred(HtmlParseError.CurrentNodeIsNotRoot, token);

                    End();
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:77,代码来源:HtmlDomBuilder.cs

示例13: AfterBody

        /// <summary>
        /// See 8.2.5.4.19 The "after body" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void AfterBody(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.Character:
                {
                    var str = token.TrimStart();
                    ReconstructFormatting();
                    AddCharacters(str);

                    if (token.IsEmpty)
                        return;
                    
                    break;
                }
                case HtmlTokenType.Comment:
                {
                    _openElements[0].AddComment(token);
                    return;
                }
                case HtmlTokenType.Doctype:
                {
                    RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
                    return;
                }
                case HtmlTokenType.StartTag:
                {
                    if (token.Name.Is(TagNames.Html))
                    {
                        InBody(token);
                        return;
                    }

                    break;
                }
                case HtmlTokenType.EndTag:
                {
                    if (token.Name.Is(TagNames.Html))
                    {
                        if (IsFragmentCase)
                            RaiseErrorOccurred(HtmlParseError.TagInvalidInFragmentMode, token);
                        else
                            _currentMode = HtmlTreeMode.AfterAfterBody;

                        return;
                    }

                    break;
                }
                case HtmlTokenType.EndOfFile:
                {
                    End();
                    return;
                }
            }

            RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
            _currentMode = HtmlTreeMode.InBody;
            InBody(token);
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:64,代码来源:HtmlDomBuilder.cs

示例14: InTemplate

        /// <summary>
        /// See 8.2.5.4.18 The "in template" insertion mode.
        /// </summary>
        /// <param name="token">The passed token.</param>
        void InTemplate(HtmlToken token)
        {
            switch (token.Type)
            {
                case HtmlTokenType.StartTag:
                {
                    var tagName = token.Name;

                    if (tagName.Is(TagNames.Script) || TagNames.AllHead.Contains(tagName))
                        InHead(token);
                    else if (TagNames.AllTableRoot.Contains(tagName))
                        TemplateStep(token, HtmlTreeMode.InTable);
                    else if (tagName.Is(TagNames.Col))
                        TemplateStep(token, HtmlTreeMode.InColumnGroup);
                    else if (tagName.Is(TagNames.Tr))
                        TemplateStep(token, HtmlTreeMode.InTableBody);
                    else if (TagNames.AllTableCells.Contains(tagName))
                        TemplateStep(token, HtmlTreeMode.InRow);
                    else
                        TemplateStep(token, HtmlTreeMode.InBody);

                    return;
                }
                case HtmlTokenType.EndTag:
                {
                    if (token.Name.Is(TagNames.Template))
                        InHead(token);
                    else
                        RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);

                    return;
                }
                case HtmlTokenType.EndOfFile:
                {
                    if (TagCurrentlyOpen(TagNames.Template))
                    {
                        RaiseErrorOccurred(HtmlParseError.EOF, token);
                        CloseTemplate();
                        Home(token);
                        return;
                    }

                    End();
                    return;
                }
                default:
                {
                    InBody(token);
                    return;
                }
            }
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:56,代码来源:HtmlDomBuilder.cs

示例15: InTableEndTagTable

 /// <summary>
 /// Act as if an table end tag has been found in the InTable state.
 /// </summary>
 /// <param name="token">The actual tag token.</param>
 /// <returns>True if the token was not ignored, otherwise false.</returns>
 Boolean InTableEndTagTable(HtmlToken token)
 {
     if (IsInTableScope(TagNames.Table))
     {
         ClearStackBackTo(TagNames.Table);
         CloseCurrentNode();
         Reset();
         return true;
     }
     else
     {
         RaiseErrorOccurred(HtmlParseError.TableNotInScope, token);
         return false;
     }
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:20,代码来源:HtmlDomBuilder.cs


注:本文中的HtmlToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。