diff --git a/index.js b/index.js index 07c78d6..94cb23d 100644 --- a/index.js +++ b/index.js @@ -108,8 +108,7 @@ export function inline(html, styles, options) { ); // Add link tags before old links - // eslint-disable-next-line array-callback-return - o.replaceStylesheets.map((href) => { + o.replaceStylesheets.forEach((href) => { const link = document.createElement('link'); link.setAttribute('rel', 'stylesheet'); @@ -144,8 +143,7 @@ export function inline(html, styles, options) { }); // Remove old links - // eslint-disable-next-line array-callback-return - removable.map((link) => { + removable.forEach((link) => { if (link.parentElement.tagName === 'NOSCRIPT') { document.remove(link.parentElement); } else { @@ -154,13 +152,16 @@ export function inline(html, styles, options) { }); } else { // Modify links and add clones to noscript block - // eslint-disable-next-line array-callback-return - links.map((link) => { + links.forEach((link) => { const href = link.getAttribute('href'); const media = link.getAttribute('media'); const type = link.getAttribute('type'); const integrity = link.getAttribute('integrity'); + if (['print', 'speech'].includes(media)) { + return; + } + if (o.extract) { const file = resolve(join(o.basePath || process.cwd, href)); diff --git a/test/expected/print.html b/test/expected/print.html new file mode 100644 index 0000000..12b2bd0 --- /dev/null +++ b/test/expected/print.html @@ -0,0 +1,20 @@ + + + + + + + + + + +
+ Test +
+ + + diff --git a/test/fixtures/print.html b/test/fixtures/print.html new file mode 100644 index 0000000..400f543 --- /dev/null +++ b/test/fixtures/print.html @@ -0,0 +1,18 @@ + + + + + + + + + +
+ Test +
+ + diff --git a/test/index.test.js b/test/index.test.js index c04a384..0bb94a0 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -820,3 +820,13 @@ test('Issue 300', async () => { expect(strip(out.toString('utf8'))).toBe(strip(expected)); }); + +test("don't add onload attribute to print stylesheet", async () => { + const html = await read('fixtures/print.html'); + const css = await read('fixtures/css/simple.css'); + + const expected = await read('expected/print.html'); + const out = inline(html, css, {strategy: 'media'}); + + expect(out.toString()).toBe(expected); +});