本文整理匯總了C#中TidyNet.Node.RemoveAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# Node.RemoveAttribute方法的具體用法?C# Node.RemoveAttribute怎麽用?C# Node.RemoveAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TidyNet.Node
的用法示例。
在下文中一共展示了Node.RemoveAttribute方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: url
/*
move presentation attribs from body to style element
background="foo" -> body { background-image: url(foo) }
bgcolor="foo" -> body { background-color: foo }
text="foo" -> body { color: foo }
link="foo" -> :link { color: foo }
vlink="foo" -> :visited { color: foo }
alink="foo" -> :active { color: foo }
*/
private void CleanBodyAttrs(Lexer lexer, Node body)
{
AttVal attr;
string bgurl = null;
string bgcolor = null;
string color = null;
attr = body.GetAttrByName("background");
if (attr != null)
{
bgurl = attr.Val;
attr.Val = null;
body.RemoveAttribute(attr);
}
attr = body.GetAttrByName("bgcolor");
if (attr != null)
{
bgcolor = attr.Val;
attr.Val = null;
body.RemoveAttribute(attr);
}
attr = body.GetAttrByName("text");
if (attr != null)
{
color = attr.Val;
attr.Val = null;
body.RemoveAttribute(attr);
}
if (bgurl != null || bgcolor != null || color != null)
{
lexer.AddStringLiteral(" body {\n");
if (bgurl != null)
{
lexer.AddStringLiteral(" background-image: url(");
lexer.AddStringLiteral(bgurl);
lexer.AddStringLiteral(");\n");
}
if (bgcolor != null)
{
lexer.AddStringLiteral(" background-color: ");
lexer.AddStringLiteral(bgcolor);
lexer.AddStringLiteral(";\n");
}
if (color != null)
{
lexer.AddStringLiteral(" color: ");
lexer.AddStringLiteral(color);
lexer.AddStringLiteral(";\n");
}
lexer.AddStringLiteral(" }\n");
}
attr = body.GetAttrByName("link");
if (attr != null)
{
AddColorRule(lexer, " :link", attr.Val);
body.RemoveAttribute(attr);
}
attr = body.GetAttrByName("vlink");
if (attr != null)
{
AddColorRule(lexer, " :visited", attr.Val);
body.RemoveAttribute(attr);
}
attr = body.GetAttrByName("alink");
if (attr != null)
{
AddColorRule(lexer, " :active", attr.Val);
body.RemoveAttribute(attr);
}
}
示例2: Style2Rule
/*
Find style attribute in node, and replace it
by corresponding class attribute. Search for
class in style dictionary otherwise gensym
new class and add to dictionary.
Assumes that node doesn't have a class attribute
*/
private void Style2Rule(Lexer lexer, Node node)
{
AttVal styleattr, classattr;
string classname;
styleattr = node.GetAttrByName("style");
if (styleattr != null)
{
classname = FindStyle(lexer, node.Element, styleattr.Val);
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;
node.RemoveAttribute(styleattr);
}
else
{
/* reuse style attribute for class attribute */
styleattr.Attribute = "class";
styleattr.Val = classname;
}
}
}
示例3: 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;
}
}
示例4: 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;
}
}
示例5: 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;
}
}