本文整理汇总了C#中HtmlToken.AsTag方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlToken.AsTag方法的具体用法?C# HtmlToken.AsTag怎么用?C# HtmlToken.AsTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlToken
的用法示例。
在下文中一共展示了HtmlToken.AsTag方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AfterHead
/// <summary>
/// See 8.2.5.4.6 The "after head" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void AfterHead(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);
return;
}
else if (tagName.Is(TagNames.Body))
{
AfterHeadStartTagBody(token.AsTag());
return;
}
else if (tagName.Is(TagNames.Frameset))
{
AddElement(new HtmlFrameSetElement(_document), token.AsTag());
_currentMode = HtmlTreeMode.InFrameset;
return;
}
else if (TagNames.AllHeadNoTemplate.Contains(tagName))
{
RaiseErrorOccurred(HtmlParseError.TagMustBeInHead, token);
var index = _openElements.Count;
var head = _document.Head as Element;
_openElements.Add(head);
InHead(token);
_openElements.Remove(head);
return;
}
else if (tagName.Is(TagNames.Head))
{
RaiseErrorOccurred(HtmlParseError.HeadTagMisplaced, token);
return;
}
break;
}
case HtmlTokenType.EndTag:
{
if (token.Name.IsOneOf(TagNames.Html, TagNames.Body, TagNames.Br))
break;
RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
return;
}
}
AfterHeadStartTagBody(HtmlTagToken.Open(TagNames.Body));
_frameset = true;
Home(token);
}
示例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);
}
示例3: InHead
/// <summary>
/// See 8.2.5.4.4 The "in head" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void InHead(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);
return;
}
else if (tagName.Is(TagNames.Meta))
{
var element = new HtmlMetaElement(_document);
AddElement(element, token.AsTag(), true);
var encoding = element.GetEncoding();
CloseCurrentNode();
if (encoding != null)
{
try
{
_document.Source.CurrentEncoding = encoding;
}
catch (NotSupportedException)
{
Restart();
}
}
return;
}
else if (TagNames.AllHeadBase.Contains(tagName))
{
AddElement(token.AsTag(), true);
CloseCurrentNode();
return;
}
else if (tagName.Is(TagNames.Title))
{
RCDataAlgorithm(token.AsTag());
return;
}
else if (tagName.IsOneOf(TagNames.Style, TagNames.NoFrames) || (_options.IsScripting && tagName.Is(TagNames.NoScript)))
{
RawtextAlgorithm(token.AsTag());
return;
}
else if (tagName.Is(TagNames.NoScript))
{
AddElement(token.AsTag());
_currentMode = HtmlTreeMode.InHeadNoScript;
return;
}
else if (tagName.Is(TagNames.Script))
{
var script = new HtmlScriptElement(_document, parserInserted: true, started: IsFragmentCase);
AddElement(script, token.AsTag());
_tokenizer.State = HtmlParseMode.Script;
_previousMode = _currentMode;
_currentMode = HtmlTreeMode.Text;
return;
}
else if (tagName.Is(TagNames.Head))
{
RaiseErrorOccurred(HtmlParseError.HeadTagMisplaced, token);
return;
}
else if (tagName.Is(TagNames.Template))
{
AddElement(new HtmlTemplateElement(_document), token.AsTag());
_formattingElements.AddScopeMarker();
_frameset = false;
_currentMode = HtmlTreeMode.InTemplate;
//.........这里部分代码省略.........
示例4: 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;
}
}
}
示例5: BeforeHtml
/// <summary>
/// See 8.2.5.4.2 The "before html" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void BeforeHtml(HtmlToken token)
{
switch (token.Type)
{
case HtmlTokenType.Character:
{
token.TrimStart();
if (token.IsEmpty)
return;
break;
}
case HtmlTokenType.Comment:
{
_document.AddComment(token);
return;
}
case HtmlTokenType.StartTag:
{
if (!token.Name.Is(TagNames.Html))
break;
AddRoot(token.AsTag());
_currentMode = HtmlTreeMode.BeforeHead;
return;
}
case HtmlTokenType.EndTag:
{
if (TagNames.AllBeforeHead.Contains(token.Name))
break;
RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
return;
}
case HtmlTokenType.Doctype:
{
RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
return;
}
}
BeforeHtml(HtmlTagToken.Open(TagNames.Html));
BeforeHead(token);
}
示例6: InSelect
/// <summary>
/// See 8.2.5.4.16 The "in select" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void InSelect(HtmlToken token)
{
switch (token.Type)
{
case HtmlTokenType.Character:
{
AddCharacters(token.Data);
return;
}
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.Option))
{
if (CurrentNode.LocalName.Is(TagNames.Option))
InSelectEndTagOption(token);
AddElement(new HtmlOptionElement(_document), token.AsTag());
}
else if (tagName.Is(TagNames.Optgroup))
{
if (CurrentNode.LocalName.Is(TagNames.Option))
InSelectEndTagOption(token);
if (CurrentNode.LocalName.Is(TagNames.Optgroup))
InSelectEndTagOptgroup(token);
AddElement(new HtmlOptionsGroupElement(_document), token.AsTag());
}
else if (tagName.Is(TagNames.Select))
{
RaiseErrorOccurred(HtmlParseError.SelectNesting, token);
InSelectEndTagSelect();
}
else if (TagNames.AllInput.Contains(tagName))
{
RaiseErrorOccurred(HtmlParseError.IllegalElementInSelectDetected, token);
if (IsInSelectScope(TagNames.Select))
{
InSelectEndTagSelect();
Home(token);
}
}
else if (tagName.IsOneOf(TagNames.Template, TagNames.Script))
{
InHead(token);
}
else
{
RaiseErrorOccurred(HtmlParseError.IllegalElementInSelectDetected, token);
}
return;
}
case HtmlTokenType.EndTag:
{
var tagName = token.Name;
if (tagName.Is(TagNames.Template))
InHead(token);
else if (tagName.Is(TagNames.Optgroup))
InSelectEndTagOptgroup(token);
else if (tagName.Is(TagNames.Option))
InSelectEndTagOption(token);
else if (tagName.Is(TagNames.Select) && IsInSelectScope(TagNames.Select))
InSelectEndTagSelect();
else if (tagName.Is(TagNames.Select))
RaiseErrorOccurred(HtmlParseError.SelectNotInScope, token);
else
RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
return;
}
case HtmlTokenType.EndOfFile:
{
InBody(token);
return;
}
default:
{
//.........这里部分代码省略.........
示例7: 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);
}
示例8: InRow
/// <summary>
/// See 8.2.5.4.14 The "in row" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void InRow(HtmlToken token)
{
switch (token.Type)
{
case HtmlTokenType.StartTag:
{
var tagName = token.Name;
if (TagNames.AllTableCells.Contains(tagName))
{
ClearStackBackTo(TagNames.Tr);
AddElement(token.AsTag());
_currentMode = HtmlTreeMode.InCell;
_formattingElements.AddScopeMarker();
}
else if (tagName.Is(TagNames.Tr) || TagNames.AllTableGeneral.Contains(tagName))
{
if (InRowEndTagTablerow(token))
InTableBody(token);
}
else
{
break;
}
return;
}
case HtmlTokenType.EndTag:
{
var tagName = token.Name;
if (tagName.Is(TagNames.Tr))
{
InRowEndTagTablerow(token);
}
else if (tagName.Is(TagNames.Table))
{
if (InRowEndTagTablerow(token))
InTableBody(token);
}
else if (TagNames.AllTableSections.Contains(tagName))
{
if (IsInTableScope(tagName))
{
InRowEndTagTablerow(token);
InTableBody(token);
}
else
RaiseErrorOccurred(HtmlParseError.TableSectionNotInScope, token);
}
else if (TagNames.AllTableSpecial.Contains(tagName))
{
RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
}
else
{
break;
}
return;
}
}
InTable(token);
}
示例9: InTableBody
/// <summary>
/// See 8.2.5.4.13 The "in table body" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void InTableBody(HtmlToken token)
{
switch (token.Type)
{
case HtmlTokenType.StartTag:
{
var tagName = token.Name;
if (tagName.Is(TagNames.Tr))
{
ClearStackBackTo(TagNames.AllTableSections);
AddElement(new HtmlTableRowElement(_document), token.AsTag());
_currentMode = HtmlTreeMode.InRow;
}
else if (TagNames.AllTableCells.Contains(tagName))
{
InTableBody(HtmlTagToken.Open(TagNames.Tr));
InRow(token);
}
else if (TagNames.AllTableGeneral.Contains(tagName))
InTableBodyCloseTable(token.AsTag());
else
break;
return;
}
case HtmlTokenType.EndTag:
{
var tagName = token.Name;
if (TagNames.AllTableSections.Contains(tagName))
{
if (IsInTableScope(tagName))
{
ClearStackBackTo(TagNames.AllTableSections);
CloseCurrentNode();
_currentMode = HtmlTreeMode.InTable;
}
else
RaiseErrorOccurred(HtmlParseError.TableSectionNotInScope, token);
}
else if (tagName.Is(TagNames.Tr) || TagNames.AllTableSpecial.Contains(tagName))
RaiseErrorOccurred(HtmlParseError.TagCannotEndHere, token);
else if (tagName.Is(TagNames.Table))
InTableBodyCloseTable(token.AsTag());
else
break;
return;
}
}
InTable(token);
}
示例10: InColumnGroup
/// <summary>
/// See 8.2.5.4.12 The "in column group" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void InColumnGroup(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.Col))
{
AddElement(new HtmlTableColElement(_document), token.AsTag(), true);
CloseCurrentNode();
}
else if (tagName.Is(TagNames.Template))
{
InHead(token);
}
else
{
break;
}
return;
}
case HtmlTokenType.EndTag:
{
var tagName = token.Name;
if (tagName.Is(TagNames.Colgroup))
InColumnGroupEndTagColgroup(token);
else if (tagName.Is(TagNames.Col))
RaiseErrorOccurred(HtmlParseError.TagClosedWrong, token);
else if (tagName.Is(TagNames.Template))
InHead(token);
else
break;
return;
}
case HtmlTokenType.EndOfFile:
{
InBody(token);
return;
}
}
if (InColumnGroupEndTagColgroup(token))
InTable(token);
}
示例11: InTable
/// <summary>
/// See 8.2.5.4.9 The "in table" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void InTable(HtmlToken token)
{
switch (token.Type)
{
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.Caption))
{
ClearStackBackTo(TagNames.Table);
_formattingElements.AddScopeMarker();
AddElement(new HtmlTableCaptionElement(_document), token.AsTag());
_currentMode = HtmlTreeMode.InCaption;
}
else if (tagName.Is(TagNames.Colgroup))
{
ClearStackBackTo(TagNames.Table);
AddElement(new HtmlTableColgroupElement(_document), token.AsTag());
_currentMode = HtmlTreeMode.InColumnGroup;
}
else if (tagName.Is(TagNames.Col))
{
InTable(HtmlTagToken.Open(TagNames.Colgroup));
InColumnGroup(token);
}
else if (TagNames.AllTableSections.Contains(tagName))
{
ClearStackBackTo(TagNames.Table);
AddElement(new HtmlTableSectionElement(_document, tagName), token.AsTag());
_currentMode = HtmlTreeMode.InTableBody;
}
else if (TagNames.AllTableCellsRows.Contains(tagName))
{
InTable(HtmlTagToken.Open(TagNames.Tbody));
InTableBody(token);
}
else if (tagName.Is(TagNames.Table))
{
RaiseErrorOccurred(HtmlParseError.TableNesting, token);
if (InTableEndTagTable(token))
Home(token);
}
else if (tagName.Is(TagNames.Input))
{
var tag = token.AsTag();
if (tag.GetAttribute(AttributeNames.Type).Isi(AttributeNames.Hidden))
{
RaiseErrorOccurred(HtmlParseError.InputUnexpected, token);
AddElement(new HtmlInputElement(_document), tag, true);
CloseCurrentNode();
}
else
{
RaiseErrorOccurred(HtmlParseError.TokenNotPossible, token);
InBodyWithFoster(token);
}
}
else if (tagName.Is(TagNames.Form))
{
RaiseErrorOccurred(HtmlParseError.FormInappropriate, token);
if (_currentFormElement == null)
{
_currentFormElement = new HtmlFormElement(_document);
AddElement(_currentFormElement, token.AsTag());
CloseCurrentNode();
}
}
else if (TagNames.AllTableHead.Contains(tagName))
{
InHead(token);
}
else
{
RaiseErrorOccurred(HtmlParseError.IllegalElementInTableDetected, token);
InBodyWithFoster(token);
}
return;
}
case HtmlTokenType.EndTag:
{
var tagName = token.Name;
//.........这里部分代码省略.........
示例12: InBody
/// <summary>
/// See 8.2.5.4.7 The "in body" insertion mode.
/// </summary>
/// <param name="token">The passed token.</param>
void InBody(HtmlToken token)
{
switch (token.Type)
{
case HtmlTokenType.Character:
{
ReconstructFormatting();
AddCharacters(token.Data);
if (token.HasContent)
_frameset = false;
return;
}
case HtmlTokenType.StartTag:
{
InBodyStartTag(token.AsTag());
return;
}
case HtmlTokenType.EndTag:
{
InBodyEndTag(token.AsTag());
return;
}
case HtmlTokenType.Comment:
{
CurrentNode.AddComment(token);
return;
}
case HtmlTokenType.Doctype:
{
RaiseErrorOccurred(HtmlParseError.DoctypeTagInappropriate, token);
return;
}
case HtmlTokenType.EndOfFile:
{
CheckBodyOnClosing(token);
if (_templateModes.Count != 0)
InTemplate(token);
else
End();
return;
}
}
}