andrewrk / juice

Juice inlines CSS stylesheets into your HTML source.
MIT License
60 stars 13 forks source link

Feature request: remove HTML classes #13

Open lolmaus opened 10 years ago

lolmaus commented 10 years ago

Hi!

My use case for Juice is preparing email newsletter templates.

We use MailChimp/Mandrill to send email newsletters. Rather than coding email templates in their web interface, i prepare them using a static site generator, with the unleashed power of Sass and Haml.

MailChimp/Mandrill guidelines insist on inlining styles, so i use Juice via gulp-inline-css. It's awesome, thank you!

The matter is that after inlining all styles i don't need HTML classes anymore. I wish Juice had an option to remove them.

andrewrk commented 10 years ago

Can you explain more explicitly what you want, maybe with an example so I can better understand?

lolmaus commented 10 years ago

Sure, i'll try once again.

My use case for Juice is to produce HTML for email newsletters.

Email newsletters have two peculiarities:

It is a nuisance to code pages with inline styles by hand. Instead, i leverage a static site generator to code pages with properly organized Haml and Sass. When the generator builds static pages, it minces them through Juice.

After all CSS has been inlined, there is no need for HTML classes. Classnames sit in the HTML code, occupying ~10% of its size, and there's absolutely no use for them. There no CSS to apply styles to them because it's all inlined, there's no JS to target them because email clients/services remove all JS.

That's why i wish i could tell Juice to strip HTML of classnames.

andrewrk commented 10 years ago

Ah ok I understand now. I think this sounds like a reasonable feature.

plummer commented 9 years ago

"all CSS should be inlined, otherwise it won't work in some email apps/web services...and there's absolutely no use for them"

This is definitely not true. Its normal to leave CSS classes in so that modern clients can target them, often this is a form of conditional css application. For example, you can use classes + non inline css to apply different styles for mobile browsers (as these render style blocks).

lolmaus commented 9 years ago

Hey @plummer, but i already have all my CSS inlined by Juice.

Note that i don't request to enforce this setting. I just request to allow enabling it manually for those people who don't need HTML classes in their email.

bravocado commented 9 years ago

I wish Juice had an option to remove them. too. :) I use the options : removeStyleTags and removeLinkTags. So, i don't need a class tag anymore in my HTML. don't you think so?

plummer commented 9 years ago

@lolmaus I suppose as an option, except it has the side effect of preventing media queries from being supported.

Also if you are using gulp / grunt, you can use a separate task that kills off classes pretty easily. I use dom_munger at the end and then run arbitrary jQuery against the document, in your case it could be like $('*').removeClass(); if you want a quick fix!

bilalkinnek commented 9 years ago

@lolmaus you can also use gulp-replace after gulp-inline-css https://www.npmjs.org/package/gulp-replace

Something like this should work: .pipe(replace(/\sclass=["'][a-zA-Z0-9_ ]*['"]/g, ''))

bravocado commented 9 years ago

@bilalkinnek awesome! thx for the solution!

lolmaus commented 9 years ago

@bilalkinnek, thank you for a handy workaround.

The point of this feature request is to use the capabilities of an HTML parser rather than relying on brute regexp.