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.CompareOrdinal(str, "javascript") == 0) || (String.CompareOrdinal(str, "jscript") == 0)) { node.AddAttribute("type", "text/javascript"); } } else { node.AddAttribute("type", "text/javascript"); } } }
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); } }
private void PrintAttrs(Out fout, int indent, Node node, AttVal attr) { if (attr != null) { if (attr.Next != null) { PrintAttrs(fout, indent, node, attr.Next); } if (attr.Attribute != null) { PrintAttribute(fout, indent, node, attr); } else if (attr.Asp != null) { AddC(' ', _linelen++); PrintAsp(fout, indent, attr.Asp); } else if (attr.Php != null) { AddC(' ', _linelen++); PrintPhp(fout, indent, attr.Php); } } /* add xml:space attribute to pre and other elements */ if (_options.XmlOut && _options.XmlSpace && ParserImpl.XmlPreserveWhiteSpace(node, _options.TagTable) && node.GetAttrByName("xml:space") == null) { PrintString(" xml:space=\"preserve\""); } }
/* 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; } }
/* This is a major clean up to strip out all the extra stuff you get when you save as web page from Word 2000. It doesn't yet know what to do with VML tags, but these will appear as errors unless you declare them as new tags, such as o:p which needs to be declared as inline. */ public virtual void CleanWord2000(Lexer lexer, Node node) { /* used to a list from a sequence of bulletted p's */ Node list = null; while (node != null) { /* discard Word's style verbiage */ if (node.Tag == _tt.TagStyle || node.Tag == _tt.TagMeta || node.Type == Node.COMMENT_TAG) { node = Node.DiscardElement(node); continue; } /* strip out all span tags Word scatters so liberally! */ if (node.Tag == _tt.TagSpan) { node = StripSpan(lexer, node); continue; } /* get rid of Word's xmlns attributes */ if (node.Tag == _tt.TagHtml) { /* check that it's a Word 2000 document */ if (node.GetAttrByName("xmlns:o") == null) { return; } } if (node.Tag == _tt.TagLink) { AttVal attr = node.GetAttrByName("rel"); if (attr != null && attr.Val != null && attr.Val.Equals("File-List")) { node = Node.DiscardElement(node); continue; } } /* discard empty paragraphs */ if (node.Content == null && node.Tag == _tt.TagP) { node = Node.DiscardElement(node); continue; } if (node.Tag == _tt.TagP) { AttVal attr = node.GetAttrByName("class"); /* map sequence of <p class="MsoListBullet"> to <ul>...</ul> */ if (attr != null && attr.Val != null && attr.Val.Equals("MsoListBullet")) { Node.CoerceNode(lexer, node, _tt.TagLi); if (list == null || list.Tag != _tt.TagUl) { list = lexer.InferredTag("ul"); Node.InsertNodeBeforeElement(node, list); } PurgeAttributes(node); if (node.Content != null) { CleanWord2000(lexer, node.Content); } /* remove node and append to contents of list */ Node.RemoveNode(node); Node.InsertNodeAtEnd(list, node); node = list.Next; } else if (attr != null && attr.Val != null && attr.Val.Equals("Code")) { /* map sequence of <p class="Code"> to <pre>...</pre> */ Node br = lexer.NewLineNode(); NormalizeSpaces(node); if (list == null || list.Tag != _tt.TagPre) { list = lexer.InferredTag("pre"); Node.InsertNodeBeforeElement(node, list); } /* remove node and append to contents of list */ Node.RemoveNode(node); Node.InsertNodeAtEnd(list, node); StripSpan(lexer, node); Node.InsertNodeAtEnd(list, br); node = list.Next; } else { list = null; } } else { list = null; } /* strip out style and class attributes */ if (node.Type == Node.START_TAG || node.Type == Node.START_END_TAG) { PurgeAttributes(node); } if (node.Content != null) { CleanWord2000(lexer, node.Content); } node = node.Next; } }
/* 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); } } }
public virtual bool CanPrune(Node element) { if (element.Type == Node.TEXT_NODE) return true; if (element.Content != null) return false; if (element.Tag == Options.TagTable.TagA && element.Attributes != null) return false; if (element.Tag == Options.TagTable.TagP && !Options.DropEmptyParas) return false; if (element.Tag == null) return false; if ((element.Tag.Model & ContentModel.ROW) != 0) return false; if (element.Tag == Options.TagTable.TagApplet) return false; if (element.Tag == Options.TagTable.TagObject) return false; if (element.Attributes != null && (element.GetAttrByName("id") != null || element.GetAttrByName("name") != null)) return false; return true; }
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); } }