Esempio n. 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)
        {
            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");
            }
        }
        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");
                }
            }
        }
Esempio n. 6
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);
            }
        }
        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");
                }
            }
        }
Esempio n. 8
0
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal    attval;
            Attribute attribute;
            bool      hasAlt     = false;
            bool      hasSrc     = false;
            bool      hasUseMap  = false;
            bool      hasIsMap   = false;
            bool      hasDataFld = false;

            node.CheckUniqueAttributes(lexer);

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

                if (attribute == AttributeTable.AttrAlt)
                {
                    hasAlt = true;
                }
                else if (attribute == AttributeTable.AttrSrc)
                {
                    hasSrc = true;
                }
                else if (attribute == AttributeTable.AttrUsemap)
                {
                    hasUseMap = true;
                }
                else if (attribute == AttributeTable.AttrIsmap)
                {
                    hasIsMap = true;
                }
                else if (attribute == AttributeTable.AttrDatafld)
                {
                    hasDataFld = true;
                }
                else if (attribute == AttributeTable.AttrWidth || attribute == AttributeTable.AttrHeight)
                {
                    lexer.versions &= ~HtmlVersion.Html20;
                }
            }

            if (!hasAlt)
            {
                lexer.badAccess |= Report.MISSING_IMAGE_ALT;
                Report.AttrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE);
                if (lexer.Options.AltText != null)
                {
                    node.AddAttribute("alt", lexer.Options.AltText);
                }
            }

            if (!hasSrc && !hasDataFld)
            {
                Report.AttrError(lexer, node, "src", Report.MISSING_ATTRIBUTE);
            }

            if (hasIsMap && !hasUseMap)
            {
                Report.AttrError(lexer, node, "ismap", Report.MISSING_IMAGEMAP);
            }
        }
Esempio n. 9
0
        /*
        Replace implicit blockquote by div with an indent
        taking care to reduce nested blockquotes to a single
        div with the indent set to match the nesting depth
        */
        public virtual void BQ2Div(Node node)
        {
            int indent;
            string indent_buf;

            while (node != null)
            {
                if (node.Tag == _tt.TagBlockquote && node.Isimplicit)
                {
                    indent = 1;

                    while (node.HasOneChild() && node.Content.Tag == _tt.TagBlockquote && node.Isimplicit)
                    {
                        ++indent;
                        StripOnlyChild(node);
                    }

                    if (node.Content != null)
                    {
                        BQ2Div(node.Content);
                    }

                    indent_buf = "margin-left: " + (2 * indent).ToString() + "em";

                    node.Element = _tt.TagDiv.Name;
                    node.Tag = _tt.TagDiv;
                    node.AddAttribute("style", indent_buf);
                }
                else if (node.Content != null)
                {
                    BQ2Div(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 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;
      }
    }
    public virtual void UnderlineToSpan(Node node)
		{
			while (node != null)
			{
				if (node.Tag == _tt.TagU)
				{
					node.Element = _tt.TagSpan.Name;
					node.Tag = _tt.TagSpan;
          node.AddAttribute("style", "text-decoration: underline;");
				}
				
				if (node.Content != null)
				{
					UnderlineToSpan(node.Content);
				}
				
				node = node.Next;
			}
		}
Esempio n. 15
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);
            }
        }
Esempio n. 16
0
        public virtual void Check(Lexer lexer, Node node)
        {
            AttVal attval;
            Attribute attribute;
            bool hasAlt = false;
            bool hasSrc = false;
            bool hasUseMap = false;
            bool hasIsMap = false;
            bool hasDataFld = false;

            node.CheckUniqueAttributes(lexer);

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

                if (attribute == AttributeTable.AttrAlt)
                {
                    hasAlt = true;
                }
                else if (attribute == AttributeTable.AttrSrc)
                {
                    hasSrc = true;
                }
                else if (attribute == AttributeTable.AttrUsemap)
                {
                    hasUseMap = true;
                }
                else if (attribute == AttributeTable.AttrIsmap)
                {
                    hasIsMap = true;
                }
                else if (attribute == AttributeTable.AttrDatafld)
                {
                    hasDataFld = true;
                }
                else if (attribute == AttributeTable.AttrWidth || attribute == AttributeTable.AttrHeight)
                {
                    lexer.versions &= ~ HtmlVersion.Html20;
                }
            }

            if (!hasAlt)
            {
                lexer.badAccess |= Report.MISSING_IMAGE_ALT;
                Report.AttrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE);
                if (lexer.Options.AltText != null)
                {
                    node.AddAttribute("alt", lexer.Options.AltText);
                }
            }

            if (!hasSrc && !hasDataFld)
            {
                Report.AttrError(lexer, node, "src", Report.MISSING_ATTRIBUTE);
            }

            if (hasIsMap && !hasUseMap)
            {
                Report.AttrError(lexer, node, "ismap", Report.MISSING_IMAGEMAP);
            }
        }