Exemple #1
0
        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");
                }
            }
        }
        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");
                }
            }
        }
        public virtual void Check(Lexer lexer, Node node)
        {
            node.CheckUniqueAttributes(lexer);

            /*
                HTML4 strict doesn't allow mixed content for
                elements with %block; as their content model
                */
            if (node.GetAttrByName("width") != null || node.GetAttrByName("height") != null)
            {
                lexer.versions &= ~ HtmlVersion.Html40Strict;
            }
        }
        public virtual void Check(Lexer lexer, Node node)
        {
            node.CheckUniqueAttributes(lexer);

            /*
             *      HTML4 strict doesn't allow mixed content for
             *      elements with %block; as their content model
             */
            if (node.GetAttrByName("width") != null || node.GetAttrByName("height") != null)
            {
                lexer.versions &= ~HtmlVersion.Html40Strict;
            }
        }
Exemple #5
0
 public virtual void Check(Lexer lexer, Node node)
 {
     if (node.GetAttrByName("src") != null)
     {
         Report.AttrError(lexer, node, "src", Report.PROPRIETARY_ATTR_VALUE);
     }
 }
 public virtual void Check(Lexer lexer, Node node)
 {
     if (node.GetAttrByName("src") != null)
     {
         Report.AttrError(lexer, node, "src", Report.PROPRIETARY_ATTR_VALUE);
     }
 }
        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");
                }
            }
        }
        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");
                }
            }
        }
        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");
            }
        }
        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");
            }
        }
Exemple #11
0
        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);
            }
        }
Exemple #12
0
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal    attval;
            Attribute attribute;
            bool      hasSummary = false;

            node.CheckUniqueAttributes(lexer);

            for (attval = node.Attributes; attval != null; attval = attval.Next)
            {
                attribute = attval.CheckAttribute(lexer, node);

                if (attribute == AttributeTable.AttrSummary)
                {
                    hasSummary = true;
                }
            }

            /* suppress warning for missing summary for HTML 2.0 and HTML 3.2 */
            if (!hasSummary && lexer.doctype != HtmlVersion.Html20 && lexer.doctype != HtmlVersion.Html32)
            {
                lexer.badAccess |= Report.MISSING_SUMMARY;
                Report.AttrError(lexer, node, "summary", Report.MISSING_ATTRIBUTE);
            }

            /* convert <table border> to <table border="1"> */
            if (lexer.Options.XmlOut)
            {
                attval = node.GetAttrByName("border");
                if (attval != null)
                {
                    if (attval.Val == null)
                    {
                        attval.Val = "1";
                    }
                }
            }
        }
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal attval;
            Attribute attribute;
            bool hasSummary = false;

            node.CheckUniqueAttributes(lexer);

            for (attval = node.Attributes; attval != null; attval = attval.Next)
            {
                attribute = attval.CheckAttribute(lexer, node);

                if (attribute == AttributeTable.AttrSummary)
                {
                    hasSummary = true;
                }
            }

            /* suppress warning for missing summary for HTML 2.0 and HTML 3.2 */
            if (!hasSummary && lexer.doctype != HtmlVersion.Html20 && lexer.doctype != HtmlVersion.Html32)
            {
                lexer.badAccess |= Report.MISSING_SUMMARY;
                Report.AttrError(lexer, node, "summary", Report.MISSING_ATTRIBUTE);
            }

            /* convert <table border> to <table border="1"> */
            if (lexer.Options.XmlOut)
            {
                attval = node.GetAttrByName("border");
                if (attval != null)
                {
                    if (attval.Val == null)
                    {
                        attval.Val = "1";
                    }
                }
            }
        }
Exemple #14
0
        /*
        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.CommentTag)
                {
                    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(lexer, 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.StartTag || node.Type == Node.StartEndTag)
                {
                    PurgeAttributes(node);
                }

                if (node.Content != null)
                {
                    CleanWord2000(lexer, node.Content);
                }

                node = node.Next;
            }
        }
Exemple #15
0
        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.tt) && node.GetAttrByName("xml:space") == null)
            {
                PrintString(fout, indent, " xml:space=\"preserve\"");
            }
        }
		/* 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);
				}
			}
		}
Exemple #17
0
        /*
        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;
                }
            }
        }
    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;
      }
    }
    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;
      }
    }
    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;
      }
    }
Exemple #21
0
        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);
            }
        }
Exemple #22
0
        /*
        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);
            }
        }
		public virtual bool CanPrune(Node element)
		{
			if (element.Type == Node.TextNode)
				return true;
			
			if (element.Content != null)
				return false;
			
			if (element.Tag == Options.tt.TagA && element.Attributes != null)
				return false;
			
			if (element.Tag == Options.tt.TagP && !Options.DropEmptyParas)
				return false;
			
			if (element.Tag == null)
				return false;
			
			if ((element.Tag.Model & ContentModel.Row) != 0)
				return false;
			
			if (element.Tag == Options.tt.TagApplet)
				return false;
			
			if (element.Tag == Options.tt.TagObject)
				return false;
			
			if (element.Attributes != null && (element.GetAttrByName("id") != null || element.GetAttrByName("name") != null))
				return false;
			
			return true;
		}