private bool UpdateCssPath(bool foundFirstCss, IDomObject element)
 {
     if (foundFirstCss == false)
     {
         element.SetAttribute("href", Globals.FullPath(_styleBundle.Path));
     }
     else
     {
         element.Remove();
     }
     return(true);
 }
Exemple #2
0
 private bool UpdateJavascriptPath(bool foundFirstScript, IDomObject element)
 {
     if (foundFirstScript == false)
     {
         element.SetAttribute("src", Globals.FullPath(_scriptBundle.Path));
     }
     else
     {
         //Just make this local, cost of removing from dom is expensive
         element.RemoveAttribute("src");
         //element.Remove();
     }
     return(true);
 }
 private bool UpdateJavascriptPath(bool foundFirstScript, IDomObject element)
 {
     if (foundFirstScript == false)
     {
         element.SetAttribute("src", Globals.FullPath(_scriptBundle.Path));
     }
     else
     {
         //Just make this local, cost of removing from dom is expensive
         element.RemoveAttribute("src");
         //element.Remove();
     }
     return true;
 }
Exemple #4
0
        private static void PrepareAttribute(IDomObject domElement, AttributeToCss attributeToCss)
        {
            string name  = attributeToCss.AttributeName;
            string value = attributeToCss.CssValue;

            //When rendering images, we need to prevent breaking the WIDTH and HEIGHT attributes. See PreMailerTests.MoveCssInline_HasStyle_DoesNotBreakImageWidthAttribute().
            //The old code could end up writing an image tag like <img width="206px"> which violates the HTML spec. It should render <img width="206">.
            if (domElement.NodeName == @"IMG" &&
                (name == "width" || name == "height") &&
                value.EndsWith("px"))
            {
                value = value.Replace("px", string.Empty);
            }

            domElement.SetAttribute(name, value);
        }
        private static void PrepareAttribute(IDomObject domElement, AttributeToCss attributeToCss)
        {
            string name = attributeToCss.AttributeName;
            string value = attributeToCss.CssValue;

            //When rendering images, we need to prevent breaking the WIDTH and HEIGHT attributes. See PreMailerTests.MoveCssInline_HasStyle_DoesNotBreakImageWidthAttribute().
            //The old code could end up writing an image tag like <img width="206px"> which violates the HTML spec. It should render <img width="206">.
            if (domElement.NodeName == @"IMG"
                && (name == "width" || name == "height")
                && value.EndsWith("px"))
            {
                value = value.Replace("px", string.Empty);
            }

            domElement.SetAttribute(name, value);
        }
Exemple #6
0
        /// <summary>
        /// Parse an HTML attribute construct: {x=["|']y["|]]} or just {x}) and add the attribute to the
        /// current element if successful. The placeholder should be tag opening construct but after the
        /// tag name. Upon exit it will be positioned after last character of attribute, or  positioned
        /// ON closing caret of tag opener if failed.
        /// </summary>
        ///
        /// <param name="html">
        /// The HTML
        /// </param>
        ///
        /// <returns>
        /// true if it succeeds, false if it fails.
        /// </returns>

        public bool GetTagAttribute(char[] html)
        {
            bool   finished  = false;
            int    step      = 0;
            string aName     = null;
            string aValue    = null;
            int    nameStart = -1;
            int    valStart  = -1;
            bool   isQuoted  = false;
            char   quoteChar = ' ';
            int    len       = html.Length;

            while (!finished && Pos < len)
            {
                char c = html[Pos];
                switch (step)
                {
                case 0:     // find name
                    if (CharacterData.IsType(c, CharacterType.HtmlTagNameStart))
                    {
                        step      = 1;
                        nameStart = Pos;
                        Pos++;
                    }
                    else if (CharacterData.IsType(c, CharacterType.HtmlTagAny))
                    {
                        finished = true;
                    }
                    else
                    {
                        Pos++;
                    }

                    break;

                case 1:
                    if (!CharacterData.IsType(c, CharacterType.HtmlTagNameExceptStart))
                    {
                        step  = 2;
                        aName = html.SubstringBetween(nameStart, Pos);
                    }
                    else
                    {
                        Pos++;
                    }
                    break;

                case 2:     // find value
                    if (CharacterData.IsType(c, CharacterType.HtmlSpace))
                    {
                        Pos++;
                        break;
                    }
                    else if (c == '=')
                    {
                        step = 3;
                        Pos++;
                    }
                    else
                    {
                        // anything else means new attribute
                        finished = true;
                        break;
                    }
                    break;

                case 3:     // find quote start
                    if (CharacterData.IsType(c, CharacterType.HtmlSpace))
                    {
                        Pos++;
                        break;
                    }
                    else
                    {
                        switch (c)
                        {
                        case '\\':
                        case '>':
                            finished = true;
                            break;

                        case '"':
                        case '\'':
                            isQuoted = true;
                            valStart = Pos + 1;
                            Pos++;
                            quoteChar = c;
                            step      = 4;
                            break;

                        default:
                            valStart = Pos;
                            step     = 4;
                            break;
                        }
                    }

                    break;

                case 4:     // parse the attribute until whitespace or closing quote
                    if ((isQuoted && c == quoteChar) ||
                        (!isQuoted && CharacterData.IsType(c, CharacterType.HtmlTagOpenerEnd)))
                    {
                        aValue = html.SubstringBetween(valStart, Pos);
                        if (isQuoted)
                        {
                            isQuoted = false;
                            Pos++;
                        }
                        finished = true;
                    }
                    else
                    {
                        Pos++;
                    }
                    break;
                }
            }
            if (aName != null)
            {
                // 12-15-11 - don't replace a valid attribute with a bad one

                if (!Element.HasAttribute(aName))
                {
                    if (aValue == null)
                    {
                        Element.SetAttribute(aName);
                    }
                    else
                    {
                        Element.SetAttribute(aName, aValue);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
 private bool UpdateCssPath(bool foundFirstCss, IDomObject element)
 {
     if (foundFirstCss == false)
     {
         element.SetAttribute("href", Globals.FullPath(_styleBundle.Path));
     }
     else
     {
         element.Remove();
     }
     return true;
 }