Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Juice not removing all <style> #470

Open
phstc opened this issue Aug 2, 2023 · 1 comment
Open

Juice not removing all <style> #470

phstc opened this issue Aug 2, 2023 · 1 comment

Comments

@phstc
Copy link

phstc commented Aug 2, 2023

I'm trying to remove all <style> from an HTML, but juice is keeping some out.

If I paste the HTML on the demo website it removes all <style> 🤷‍♂️

I'm using juice 9.1.0.

Sample RunKit https://runkit.com/embed/fjqdnm3ckkdv (change the output from Rendered HTML to Full Text)

const fs = require('fs');
const juice = require('juice');

const rawHtml = `
  <!DOCTYPE html>
  <html>
  <head>
    <style>
a:hover {
  color: #000 !important;
}
a:active {
  color: #000 !important;
}
a:visited {
  text-decoration: none;
  color: #00c8b4 !important;
}
@media only screen and (max-width: 600px) {
  table[class="body"] img {
    height: auto !important;
    width: auto !important;
  }
}

    </style>
  </head>
  <body>
    Test!!!
  </body>
  </html>
`;

const juiceHtml = juice(rawHtml)
console.log(juiceHtml)

/*

OUTPUT:

  <!DOCTYPE html>
  <html>
  <head>
    <style>
a:hover {
  color: #000 !important;
}
a:active {
  color: #000 !important;
}
a:visited {
  text-decoration: none;
  color: #00c8b4 !important;
}
@media only screen and (max-width: 600px) {
  table[class="body"] img {
    height: auto !important;
    width: auto !important;
  }
}
</style>
  </head>
  <body>
    Test!!!
  </body>
  </html>


*/

Any ideas on what it could be?

I did try with the same options as on the demo website, but still, it did not work. The most important option is removeStyleTags, but that's true by default.

@phstc
Copy link
Author

phstc commented Aug 7, 2023

Great troubleshooting by Marco on StackOverflow https://stackoverflow.com/a/76829914/464685

Apparently, the webversion of juice uses an extremely outdated version which gives a different behaviour because a different CSS parser is used.

This seems to be a big regression compared with the demo website. The only version I could reproduce the demo website output (not keeping style tags) was version 1.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant