diff --git a/src/transformers/removeInlinedSelectors.js b/src/transformers/removeInlinedSelectors.js index faeb5e83..ec484ae0 100644 --- a/src/transformers/removeInlinedSelectors.js +++ b/src/transformers/removeInlinedSelectors.js @@ -10,10 +10,10 @@ module.exports = async (html, config = {}) => { } const posthtmlOptions = get(config, 'build.posthtml.options', {}) - return posthtml([plugin()]).process(html, posthtmlOptions).then(result => result.html) + return posthtml([plugin(posthtmlOptions)]).process(html, posthtmlOptions).then(result => result.html) } -const plugin = () => tree => { +const plugin = posthtmlOptions => tree => { const process = node => { // For each style tag... if (node.tag === 'style') { @@ -57,6 +57,13 @@ const plugin = () => tree => { n.attrs = parsedAttrs.compose() + // Fix issue with .compose() automatically quoting attributes with no values + Object.entries(n.attrs).forEach(([name, value]) => { + if (value === '' && get(posthtmlOptions, 'recognizeNoValueAttribute') === true) { + n.attrs[name] = true + } + }) + return n }) } catch {} diff --git a/test/test-transformers.js b/test/test-transformers.js index f8fbe1cf..be0828f0 100644 --- a/test/test-transformers.js +++ b/test/test-transformers.js @@ -427,7 +427,7 @@ test('remove inlined selectors', async t => { -
+

Title

text
@@ -435,7 +435,7 @@ test('remove inlined selectors', async t => { ` - const expected = ` + const expectedWithOptions = ` -
+

Title

text
@@ -469,9 +469,22 @@ test('remove inlined selectors', async t => { ` - const result = await Maizzle.removeInlinedClasses(html) + const withPostHTMLOptions = await Maizzle.removeInlinedClasses(html, { + build: { + posthtml: { + options: { + recognizeNoValueAttribute: true + } + } + } + }) + + const basic = await Maizzle.removeInlinedClasses(html) - t.is(result, expected) + const expectedBasic = expectedWithOptions.replace('no-value', 'no-value=""') + + t.is(withPostHTMLOptions, expectedWithOptions) + t.is(basic, expectedBasic) }) test('remove inlined selectors (disabled)', async t => {