-
Notifications
You must be signed in to change notification settings - Fork 84
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
Move media quesries inside a CSS file to a <style> element #113
Comments
Any solutions? |
Because of this issue I don't use linked style files. But it would be great if I can use. A workaround might be preprocessing the file to replace style links with style content. This should be a simple task but I could not find a ready-made solution for it. |
This is what I did
import * as getHrefContent from "href-content";
import * as getStylesheetList from "list-stylesheets";
import * as mediaQueryText from "mediaquery-text";
import { promisify } from "util";
const getHrefContentAsync = promisify(getHrefContent);
export async function extractMediaQueriesCss(html: string, options) {
const data = getStylesheetList(html, options);
let mediaCss = [];
for (const href of data.hrefs) {
const linkedStyle = await getHrefContentAsync(href, options.url);
mediaCss.push(mediaQueryText(linkedStyle));
}
return mediaCss.join("\n");
}
const inlineCssOptions = {
url: `file://${templateFile}`,
preserveMediaQueries: true,
applyLinkTags: true,
};
const extraCss = await extractMediaQueriesCss(templateContent, inlineCssOptions);
// inline the linked CSS mediaquery rules inside the html itself
templateContent = templateContent.replace("</head>", `<style type="text/css">${extraCss}</style></head>`);
templateContent = await inlineCss(templateContent, inlineCssOptions); |
How do I convert @media css to inline style ? |
My request is as follows:
When you have an HTML file that uses
<link />
, to a CSS file, and it has @media queries, have an option to move the media queries to a<style>
element.The reason for this request is that now if you have a media query inside the
style.css
file, it will either:<link />
file, which is mostly not supported in email clientsFor example:
style.css
email.html
After processing the file, via inline-css, with the option
preserveMediaQueries: true
the file would be as such:email-inline-css.html
All the inline CSS rules would apply and the media queries would be moved to a
<style>
element.Thank you for the great package.
The text was updated successfully, but these errors were encountered: