/* 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) { string bgurl = null; string bgcolor = null; string color = null; AttVal 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); } }
/* 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 = node.GetAttrByName("style"); if (styleattr == null) return; string classname = FindStyle(lexer, node.Element, styleattr.Val); 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; node.RemoveAttribute(styleattr); } else { /* reuse style attribute for class attribute */ styleattr.Attribute = "class"; styleattr.Val = classname; } }