本文整理汇总了C#中TidyNet.Lexer.AddStringLiteral方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.AddStringLiteral方法的具体用法?C# Lexer.AddStringLiteral怎么用?C# Lexer.AddStringLiteral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TidyNet.Lexer
的用法示例。
在下文中一共展示了Lexer.AddStringLiteral方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddColorRule
private void AddColorRule(Lexer lexer, string selector, string color)
{
if (color != null)
{
lexer.AddStringLiteral(selector);
lexer.AddStringLiteral(" { color: ");
lexer.AddStringLiteral(color);
lexer.AddStringLiteral(" }\n");
}
}
示例2: 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);
}
}
示例3: CreateStyleElement
/* create style element using rules from dictionary */
private void CreateStyleElement(Lexer lexer, Node doc)
{
Node node, head, body;
Style style;
AttVal av;
if (lexer.styles == null && NiceBody(lexer, doc))
{
return;
}
node = lexer.NewNode(Node.StartTag, null, 0, 0, "style");
node.Isimplicit = true;
/* insert type attribute */
av = new AttVal(null, null, '"', "type", "text/css");
av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av);
node.Attributes = av;
body = doc.FindBody(lexer.Options.tt);
lexer.txtstart = lexer.lexsize;
if (body != null)
{
CleanBodyAttrs(lexer, body);
}
for (style = lexer.styles; style != null; style = style.Next)
{
lexer.AddCharToLexer(' ');
lexer.AddStringLiteral(style.Tag);
lexer.AddCharToLexer('.');
lexer.AddStringLiteral(style.TagClass);
lexer.AddCharToLexer(' ');
lexer.AddCharToLexer('{');
lexer.AddStringLiteral(style.Properties);
lexer.AddCharToLexer('}');
lexer.AddCharToLexer('\n');
}
lexer.txtend = lexer.lexsize;
Node.InsertNodeAtEnd(node, lexer.NewNode(Node.TextNode, lexer.lexbuf, lexer.txtstart, lexer.txtend));
/*
now insert style element into document head
doc is root node. search its children for html node
the head node should be first child of html node
*/
head = doc.FindHead(lexer.Options.tt);
if (head != null)
{
Node.InsertNodeAtEnd(head, node);
}
}