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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/mjml-core/src/helpers/mediaQueries.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { map, isEmpty } from 'lodash'

// eslint-disable-next-line import/prefer-default-export
export default function buildMediaQueriesTags(breakpoint, mediaQueries = {}, forceOWADesktop = false) {
export default function buildMediaQueriesTags(breakpoint, mediaQueries = {}, options = {}) {
if (isEmpty(mediaQueries)) {
return ''
}

const {
forceOWADesktop = false,
printerSupport = false,
} = options

const baseMediaQueries = map(
mediaQueries,
(mediaQuery, className) => `.${className} ${mediaQuery}`,
Expand All @@ -25,6 +30,15 @@ export default function buildMediaQueriesTags(breakpoint, mediaQueries = {}, for
<style media="screen and (min-width:${breakpoint})">
${thunderbirdMediaQueries.join('\n')}
</style>
${
printerSupport
? `<style type="text/css">
@media only print {
${baseMediaQueries.join('\n')}
}
</style>`
: ``
}
${
forceOWADesktop
? `<style type="text/css">\n${owaQueries.join('\n')}\n</style>`
Expand Down
6 changes: 5 additions & 1 deletion packages/mjml-core/src/helpers/skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function skeleton(options) {
title = '',
style = [],
forceOWADesktop,
printerSupport,
inlineStyle,
lang,
dir,
Expand Down Expand Up @@ -59,7 +60,10 @@ export default function skeleton(options) {
</style>
<![endif]-->
${buildFontsTags(content, inlineStyle, fonts)}
${buildMediaQueriesTags(breakpoint, mediaQueries, forceOWADesktop)}
${buildMediaQueriesTags(breakpoint, mediaQueries, {
forceOWADesktop,
printerSupport,
})}
${buildStyleFromComponents(breakpoint, componentsHeadStyle, headStyle)}
${buildStyleFromTags(breakpoint, style)}
${headRaw.filter(negate(isNil)).join('\n')}
Expand Down
2 changes: 2 additions & 0 deletions packages/mjml-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function mjml2html(mjml, options = {}) {
noMigrateWarn = false,
preprocessors,
presets = [],
printerSupport = false,
} = {
...mjmlConfigOptions,
...options,
Expand Down Expand Up @@ -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',

})

if (globalData.inlineStyle.length > 0) {
Expand Down