本文整理汇总了C#中TidyNet.Node.AddAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Node.AddAttribute方法的具体用法?C# Node.AddAttribute怎么用?C# Node.AddAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TidyNet.Node
的用法示例。
在下文中一共展示了Node.AddAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Check
public virtual void Check(Lexer lexer, Node node)
{
node.CheckUniqueAttributes(lexer);
AttVal lang = node.GetAttrByName("language");
AttVal type = node.GetAttrByName("type");
if (type == null)
{
Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);
/* check for javascript */
if (lang != null)
{
string str = lang.Val;
if (str.Length > 10)
{
str = str.Substring(0, 10);
}
if ((String.Compare(str, "javascript") == 0) || (String.Compare(str, "jscript") == 0))
{
node.AddAttribute("type", "text/javascript");
}
}
else
{
node.AddAttribute("type", "text/javascript");
}
}
}
示例2: Check
public virtual void Check(Lexer lexer, Node node)
{
AttVal type = node.GetAttrByName("type");
node.CheckUniqueAttributes(lexer);
if (type == null)
{
Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);
node.AddAttribute("type", "text/css");
}
}
示例3: Check
public virtual void Check(Lexer lexer, Node node)
{
AttVal rel = node.GetAttrByName("rel");
node.CheckUniqueAttributes(lexer);
if (rel != null && rel.Val != null && rel.Val.Equals("stylesheet"))
{
AttVal type = node.GetAttrByName("type");
if (type == null)
{
Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);
node.AddAttribute("type", "text/css");
}
}
}
示例4: BQ2Div
/*
Replace implicit blockquote by div with an indent
taking care to reduce nested blockquotes to a single
div with the indent set to match the nesting depth
*/
public virtual void BQ2Div(Node node)
{
int indent;
string indent_buf;
while (node != null)
{
if (node.Tag == _tt.TagBlockquote && node.Isimplicit)
{
indent = 1;
while (node.HasOneChild() && node.Content.Tag == _tt.TagBlockquote && node.Isimplicit)
{
++indent;
StripOnlyChild(node);
}
if (node.Content != null)
{
BQ2Div(node.Content);
}
indent_buf = "margin-left: " + (2 * indent).ToString() + "em";
node.Element = _tt.TagDiv.Name;
node.Tag = _tt.TagDiv;
node.AddAttribute("style", indent_buf);
}
else if (node.Content != null)
{
BQ2Div(node.Content);
}
node = node.Next;
}
}
示例5: CleanTableAttrs
public virtual void CleanTableAttrs(Node node)
{
while (node != null)
{
if (node.Tag == _tt.TagTr || node.Tag == _tt.TagTh || node.Tag == _tt.TagTd) //TODO: add tbody?
{
AttVal attr;
string bgurl = null;
string bgcolor = null;
string height = null;
string width = null;
attr = node.GetAttrByName("background");
if (attr != null)
{
bgurl = attr.Val;
attr.Val = null;
node.RemoveAttribute(attr);
}
attr = node.GetAttrByName("bgcolor");
if (attr != null)
{
bgcolor = attr.Val;
attr.Val = null;
node.RemoveAttribute(attr);
}
attr = node.GetAttrByName("width");
if (attr != null)
{
width = attr.Val;
attr.Val = null;
node.RemoveAttribute(attr);
}
attr = node.GetAttrByName("height");
if (attr != null)
{
height = attr.Val;
attr.Val = null;
node.RemoveAttribute(attr);
}
if (bgurl != null || bgcolor != null || width != null || height != null)
{
string style = string.Empty;
if (bgurl != null)
{
style += "background-image:url(" + bgurl + ");";
}
if (bgcolor != null)
{
style += "background-color:"+ bgcolor +";";
}
if (width != null)
{
style += "width:" + width + ";";
}
if (height != null)
{
style += "height:" + height + ";";
}
node.AddAttribute("style", style);
}
}
if (node.Content != null)
{
CleanTableAttrs(node.Content);
}
node = node.Next;
}
}
示例6: FixId
/* duplicate name attribute as an id */
public virtual void FixId(Node node)
{
AttVal name = node.GetAttrByName("name");
AttVal id = node.GetAttrByName("id");
if (name != null)
{
if (id != null)
{
if (!id.Val.Equals(name.Val))
{
Report.AttrError(this, node, "name", Report.ID_NAME_MISMATCH);
}
}
else if (Options.XmlOut)
{
node.AddAttribute("id", name.Val);
}
}
}
示例7: CleanImgAttrs
public virtual void CleanImgAttrs(Node node)
{
while (node != null)
{
if (node.Tag == _tt.TagImg)
{
string style = string.Empty;
AttVal attr = node.GetAttrByName("border");
if (attr != null)
{
style += "border-width:" + attr.Val + ";";
attr.Val = null;
node.RemoveAttribute(attr);
}
attr = node.GetAttrByName("align");
if (attr != null)
{
style += "float:" + attr.Val + ";";
attr.Val = null;
node.RemoveAttribute(attr);
}
attr = node.GetAttrByName("height");
if (attr != null)
{
style += "height:" + attr.Val + ";";
attr.Val = null;
node.RemoveAttribute(attr);
}
attr = node.GetAttrByName("width");
if (attr != null)
{
style += "width:" + attr.Val + ";";
attr.Val = null;
node.RemoveAttribute(attr);
}
//xhtml requires the alt attribute
attr = node.GetAttrByName("alt");
if (attr == null)
{
node.AddAttribute("alt", string.Empty);
}
attr = node.GetAttrByName("style");
if (style.Length > 0)
{
if (attr != null && !string.IsNullOrEmpty(attr.Val))
{
style = style + attr.Val;
attr.Val = null;
node.RemoveAttribute(attr);
}
node.AddAttribute("style", style);
}
}
if (node.Content != null)
{
CleanImgAttrs(node.Content);
}
node = node.Next;
}
}
示例8: CleanAnchorTarget
public virtual void CleanAnchorTarget(Node node)
{
while (node != null)
{
if (node.Tag == _tt.TagA)
{
AttVal attr = node.GetAttrByName("target");
if (attr != null)
{
if (attr.Val.ToLower() == "_blank")
{
AttVal rel = node.GetAttrByName("rel");
if (rel == null) node.AddAttribute("rel", "external");
else rel.Val += " external";
}
node.RemoveAttribute(attr);
}
}
if (node.Content != null)
{
CleanAnchorTarget(node.Content);
}
node = node.Next;
}
}
示例9: UnderlineToSpan
public virtual void UnderlineToSpan(Node node)
{
while (node != null)
{
if (node.Tag == _tt.TagU)
{
node.Element = _tt.TagSpan.Name;
node.Tag = _tt.TagSpan;
node.AddAttribute("style", "text-decoration: underline;");
}
if (node.Content != null)
{
UnderlineToSpan(node.Content);
}
node = node.Next;
}
}
示例10: AddClass
public static void AddClass(Node node, string classname)
{
AttVal classattr = node.GetAttrByName("class");
/*
if there already is a class attribute
then append class name after a space
*/
if (classattr != null)
{
classattr.Val = classattr.Val + " " + classname;
}
/* create new class attribute */
else
{
node.AddAttribute("class", classname);
}
}
示例11: Check
public virtual void Check(Lexer lexer, Node node)
{
AttVal attval;
Attribute attribute;
bool hasAlt = false;
bool hasSrc = false;
bool hasUseMap = false;
bool hasIsMap = false;
bool hasDataFld = false;
node.CheckUniqueAttributes(lexer);
for (attval = node.Attributes; attval != null; attval = attval.Next)
{
attribute = attval.CheckAttribute(lexer, node);
if (attribute == AttributeTable.AttrAlt)
{
hasAlt = true;
}
else if (attribute == AttributeTable.AttrSrc)
{
hasSrc = true;
}
else if (attribute == AttributeTable.AttrUsemap)
{
hasUseMap = true;
}
else if (attribute == AttributeTable.AttrIsmap)
{
hasIsMap = true;
}
else if (attribute == AttributeTable.AttrDatafld)
{
hasDataFld = true;
}
else if (attribute == AttributeTable.AttrWidth || attribute == AttributeTable.AttrHeight)
{
lexer.versions &= ~ HtmlVersion.Html20;
}
}
if (!hasAlt)
{
lexer.badAccess |= Report.MISSING_IMAGE_ALT;
Report.AttrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE);
if (lexer.Options.AltText != null)
{
node.AddAttribute("alt", lexer.Options.AltText);
}
}
if (!hasSrc && !hasDataFld)
{
Report.AttrError(lexer, node, "src", Report.MISSING_ATTRIBUTE);
}
if (hasIsMap && !hasUseMap)
{
Report.AttrError(lexer, node, "ismap", Report.MISSING_IMAGEMAP);
}
}