Code Monkey home page Code Monkey logo

Comments (8)

martinnormark avatar martinnormark commented on May 23, 2024

Can you debug and find out the string passed to AngleSharp´s QuerySelectorAll method, in FindElementsWithStyles when it fails?

As a workaround now, use the v1.4.3 tag - the current version on Nu Get, which uses the old HTML parser instead of AngleSharp introduced in #76.

from premailer.net.

arbh89 avatar arbh89 commented on May 23, 2024

The string passed was @Keyframes progress-bar-stripes, i found that the error is when the selector starts with @, i added the next validation to the method FindElementsWithStyles.

foreach (var style in stylesToApply)
{
if (!style.Value.Name.StartsWith("@"))
{
var elementsForSelector = _document.QuerySelectorAll(style.Value.Name);

                foreach (var el in elementsForSelector)
                {
                    var existing = result.ContainsKey(el) ? result[el] : new List<StyleClass>();
                    existing.Add(style.Value);
                    result[el] = existing;
                }
            }
        }

Now it is working.

from premailer.net.

CodeAnimal avatar CodeAnimal commented on May 23, 2024

@martinnormark You said in #78 that you're waiting on this issue to be sorted before a NuGet release with the new AngelSharp. Is there any idea when this will be? I'm actually getting the same issue as #9 and I'm hoping the AngelSharp switch will fix this.

from premailer.net.

martinnormark avatar martinnormark commented on May 23, 2024

Have you tried verifying using current master branch, and writing a test case for it?

Haven't looked further into a general way of solving this issue yet.

from premailer.net.

arbh89 avatar arbh89 commented on May 23, 2024

I have downloaded bootstrap from here https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css to my C drive and have added the next test case to PreMailerTests.cs to reproduce the error.

        public void MoveCssInline_BootstrapFramework()
        {
            string input = "<html lang=\"en\"><head></head><body><div class=\"container\"><form class=\"form-signin\"><h2 class=\"form-signin-heading\">Please sign in</h2><label for=\"inputEmail\" class=\"sr-only\">Email address</label><input type=\"email\" id=\"inputEmail\" class=\"form-control\" placeholder=\"Email address\" required=\"\" autofocus=\"\"><label for=\"inputPassword\" class=\"sr-only\">Password</label><input type=\"password\" id=\"inputPassword\" class=\"form-control\" placeholder=\"Password\" required=\"\"><div class=\"checkbox\"><label><input type=\"checkbox\" value=\"remember-me\"> Remember me</label></div><button class=\"btn btn-lg btn-primary btn-block\" type=\"submit\">Sign in</button></form></div> <!-- /container --></body></html>";

            string bootstrapFrameworkContent = File.ReadAllText("C:\\bootstrap.min.css");

            var premailedOutput = PreMailer.MoveCssInline(input, css: bootstrapFrameworkContent);

            Assert.IsTrue(premailedOutput.Html.Contains("<html lang=\"en\">"));
        }

from premailer.net.

CodeAnimal avatar CodeAnimal commented on May 23, 2024

@arbh89 Is that method to test #9? Or for this issue? I'll see if I can find some time to write up a test case if not (although I'm crazy busy at the minute).

from premailer.net.

martinnormark avatar martinnormark commented on May 23, 2024

This issue. There's a comment with markup to test #9 in that issue: #9 (comment)

from premailer.net.

martinnormark avatar martinnormark commented on May 23, 2024

As a catch all, I've wrapped querying DOM elements by CSS selector in a try-catch block, adding to the warnings array of the result the failed selectors.

For this particular issue, note that even the minified Bootstrap CSS is a 118 KB footprint in every email you sent.

Currently PreMailer does not parse a keyframe block correctly, since each percentage step within will become their own selector. It should probably identify blocks such as this as unsupported selectors, and force it into the actual style block of the email so that animations will work - regardless of the removeStyleElements flag.

from premailer.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.