From 0c6d9e95e301cd1ea72d16f7d9a8f1cb07ab42e6 Mon Sep 17 00:00:00 2001 From: Cosmin Popovici Date: Thu, 20 Oct 2022 13:00:45 +0300 Subject: [PATCH] fix: lowercase tag names in keepOnlyAttributeSizes --- src/transformers/removeInlineSizes.js | 5 ++--- test/test-transformers.js | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/transformers/removeInlineSizes.js b/src/transformers/removeInlineSizes.js index 2fc377a6..5f497f54 100644 --- a/src/transformers/removeInlineSizes.js +++ b/src/transformers/removeInlineSizes.js @@ -19,12 +19,11 @@ module.exports = async (html, config = {}, direct = false) => { const removeInlineSizes = (mappings = {}) => tree => { const process = node => { const attrs = parseAttrs(node.attrs) - const tag = node.tag ? node.tag.toUpperCase() : '' Object.entries(mappings).forEach(([attribute, tags]) => { - tags = Object.values(tags) + tags = Object.values(tags).map(tag => tag.toLowerCase()) - if (!tags.includes(tag)) { + if (!tags.includes(node.tag)) { return node } diff --git a/test/test-transformers.js b/test/test-transformers.js index 05f11edf..4e846b01 100644 --- a/test/test-transformers.js +++ b/test/test-transformers.js @@ -13,13 +13,24 @@ const expected = file => readFile('expected/transformers', file) test('remove inline sizes', async t => { const options = { - width: ['TD'], - height: ['TD'] + width: ['table'], + height: ['td'] } - const html = await Maizzle.removeInlineSizes('test', options) + const html = await Maizzle.removeInlineSizes(` + + + + +
test
`, + options) - t.is(html, 'test') + t.is(html, ` + + + + +
test
`) }) test('remove inline background-color', async t => {