From aae48131a0fa5941d0a0a34c86b50b2cb3cd0e27 Mon Sep 17 00:00:00 2001 From: Cosmin Popovici Date: Wed, 12 Oct 2022 14:15:49 +0300 Subject: [PATCH] fix: remove empty style tags --- src/transformers/removeInlinedSelectors.js | 7 +++- test/test-transformers.js | 43 ++++++++++++++++------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/transformers/removeInlinedSelectors.js b/src/transformers/removeInlinedSelectors.js index b76f256f..a0ecfe6d 100644 --- a/src/transformers/removeInlinedSelectors.js +++ b/src/transformers/removeInlinedSelectors.js @@ -71,7 +71,12 @@ const plugin = posthtmlOptions => tree => { } catch {} }) - node.content = root.toString() + node.content = root.toString().trim() + + // Remove - + } +
@@ -529,6 +525,30 @@ test('remove inlined selectors', async t => { ` + const html2 = ` + + + + + + ` + + const expectedNoEmptyStyleTags = ` + + + + + + ` + + const basic = await Maizzle.removeInlinedClasses(html) + const noEmptyStyle = await Maizzle.removeInlinedClasses(html2) + const withPostHTMLOptions = await Maizzle.removeInlinedClasses(html, { build: { posthtml: { @@ -539,10 +559,9 @@ test('remove inlined selectors', async t => { } }) - const basic = await Maizzle.removeInlinedClasses(html) - - t.is(withPostHTMLOptions, expectedWithOptions) - t.is(basic, expectedWithOptions) + t.is(basic, expectedHTML) + t.is(withPostHTMLOptions, expectedHTML) + t.is(noEmptyStyle, expectedNoEmptyStyleTags) }) test('remove inlined selectors (disabled)', async t => {