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

Optionally ignore style tags in HTML, accept additional argument for css to inline? #45

Closed
cheapsteak opened this issue Jul 11, 2020 · 4 comments

Comments

@cheapsteak
Copy link
Contributor

👋 Hi there :)

Have you considered allowing css to inline be passed as an additional parameter?

(This might be related to #10 , but not quite the same)

The use case I'm thinking of is to possibly replace juice in mjml (I'm not affiliated, just a lib user), where css specified in <mj-style inline="inline"> is collected as a separate string that's currently passed into juice as extraCss, and inlining of other css is disabled (which makes sense because sometimes you do want to tell clients that respect style sheets to do something different from outlook)

https://github.com/mjmlio/mjml/blob/246df840f4d0fcd812e51ca55bd6bef6592cb0e6/packages/mjml-core/src/index.js#L317-L319

@Stranger6667
Copy link
Owner

Hi @cheapsteak !

I didn't think about it, but having such a feature seems perfectly reasonable to me :) Correct me if I am wrong, but to support your use case, it might be:

  • A InlineOptions option to disable "style" tag inlining;
  • A InlineOptions option with extra CSS to inline;

As far as I see, the extra CSS should be in the form of qualified rules as a single string, e.g. h1 {color: green}, is it in this way in mjml?
Also, from looking at the code sample you mentioned I am not sure what insertPreservedExtraCss option does? Could you, please, help me with that?

If the things above make sense, then I can implement that :) And I will appreciate if you can provide some input, expected output samples so I can include them to the test suite :)

Cheers

@cheapsteak
Copy link
Contributor Author

cheapsteak commented Jul 11, 2020

A InlineOptions option to disable "style" tag inlining;
A InlineOptions option with extra CSS to inline;

yes that should work!

the extra CSS should be in the form of qualified rules as a single string, e.g. h1 {color: green}, is it in this way in mjml?

yup!

insertPreservedExtraCss

that's a "juice" parameter , i'll copy their description here :)

whether to insert into the document any preserved @media or @font-face content from extraCss when using preserveMediaQueries, preserveFontFaces or preserveKeyFrames. When true order of preference to append the <style> element is into head, then body, then at the end of the document. When a string the value is treated as a CSS/jQuery/cheerio selector, and when found, the <style> tag will be appended to the end of the first match. Defaults to true.

for emails, extra CSS passed in separately from the html that can't be inlined should probably be thrown away, which I guess is why mjml had disabled that :)

@Stranger6667
Copy link
Owner

Thanks! I implemented the abovementioned options - inline_style_tags & extra_css (in #46 and #48 ). Is there anything else I can do regarding this feature?

I think that a new release could be issued when #49 is done so you can directly use it as a replacement for juice :) What do you think?

@cheapsteak
Copy link
Contributor Author

those look awesome!!! please feel free to close this issue :)

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

2 participants