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

fix(mjml-core): add print to media queries #2677

Merged
merged 3 commits into from
Aug 28, 2023

Conversation

jimmyfortinx
Copy link
Contributor

@jimmyfortinx jimmyfortinx commented Apr 26, 2023

Context:
We want to be able to use mjml to generate our invoice/statement and print them as PDF. We already have an wysiwyg editor that generates mjml for our emails and we would like to reuse it to have an editor over our invoice/statement as well.


I know the current state of my PR is not enough to have it approved and merged. I already have talked with @iRyusa in Slack and he shared his concerns around breaking email clients. I would need your help to get this PR fully tested, I'm not asking you to do it for us, but I would need some guidance.

  • Could we use someone's account to get all screenshots rendered through Litmus or Email On Acid? (since we don't own any at this moment).
  • Do you already have one or multiple mjml that we could use that would ensure we are testing all your components and not introducing breaking changes?

Once those questions will be answered, we will be pleased to make all the tests required to get this PR approved.

Thanks in advance for the people that will be involved in that PR.


When the option printerSupport is not provided it does not introduce any breaking changes

const finalMjml = mjml2html(mjmlWithVariables);

But when you want to fix the layout to support printers you just have to add the option like that:

const finalMjml = mjml2html(mjmlWithVariables, { printerSupport: true });

PR for Typescript: DefinitelyTyped/DefinitelyTyped#65463

Result in Chrome using plain html:
image

Result when printing it as a PDF:

Before After
image image
before-fix.pdf after-fix.pdf

@@ -18,7 +18,7 @@ export default function buildMediaQueriesTags(breakpoint, mediaQueries = {}, for

return `
<style type="text/css">
@media only screen and (min-width:${breakpoint}) {
@media only screen and (min-width:${breakpoint}), print {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can isolate them inside it's own style to ensure it won't break anything and add an attribute on mjml tag to disable it by default and only add them if needed like owa media queriees

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of disabling it by default. I'll try to figure out a way to achieve your suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iRyusa I applied what you've suggested and it worked perfectly. Like me know if it needs modification and what would the next steps.

@@ -373,6 +374,7 @@ export default function mjml2html(mjml, options = {}) {
content = skeleton({
content,
...globalData,
printerSupport,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know forceOWADesktop parameter was getting the value through the attributes, but in my case it would be better to get it from the options. I guess that would not really be an issue.

forceOWADesktop: get(mjml, 'attributes.owa', 'mobile') === 'desktop',

Copy link
Member

@iRyusa iRyusa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM we should be able to merge this soon

@iRyusa iRyusa merged commit 33ed4f0 into mjmlio:master Aug 28, 2023
@jimmyfortinx jimmyfortinx deleted the printer-support branch June 25, 2024 12:56
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

Successfully merging this pull request may close these issues.

2 participants