Skip to content

Commit

Permalink
fix: lowercase tag names in keepOnlyAttributeSizes
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin committed Oct 20, 2022
1 parent 5e2eefd commit 0c6d9e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/transformers/removeInlineSizes.js
Expand Up @@ -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
}

Expand Down
19 changes: 15 additions & 4 deletions test/test-transformers.js
Expand Up @@ -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('<td style="width:100%;height:10px;">test</td>', options)
const html = await Maizzle.removeInlineSizes(`
<table style="width: 10px; height: auto;">
<tr>
<td style="width: 100%; height: 10px;">test</td>
</tr>
</table>`,
options)

t.is(html, '<td style="">test</td>')
t.is(html, `
<table style="height: auto">
<tr>
<td style="width: 100%">test</td>
</tr>
</table>`)
})

test('remove inline background-color', async t => {
Expand Down

0 comments on commit 0c6d9e9

Please sign in to comment.