Skip to content

Commit

Permalink
refactor: remove inline sizes transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin committed Oct 8, 2022
1 parent a8a1299 commit 1eec925
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/transformers/removeInlineSizes.js
@@ -1,6 +1,7 @@
const posthtml = require('posthtml')
const {get, isEmpty} = require('lodash')
const parseAttrs = require('posthtml-attrs-parser')
const {toStyleString} = require('../utils/helpers')

module.exports = async (html, config = {}, direct = false) => {
const settings = direct ? config : get(config, 'inlineCSS.keepOnlyAttributeSizes', {})
Expand All @@ -26,14 +27,14 @@ const removeInlineSizes = (mappings = {}) => tree => {
}

tags.forEach(() => {
if (attrs.style) {
if (get(node, 'attrs.style')) {
delete attrs.style[attribute]

node.attrs.style = toStyleString(attrs.style)
}
})
})

node.attrs = attrs.compose()

return node
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/helpers.js
Expand Up @@ -13,5 +13,6 @@ module.exports = {
}
},
// https://github.com/lukeed/console-clear
clearConsole: () => process.stdout.write('\x1B[H\x1B[2J')
clearConsole: () => process.stdout.write('\x1B[H\x1B[2J'),
toStyleString: (object = {}) => Object.entries(object).map(([k, v]) => `${k}: ${v}`).join('; ')
}

0 comments on commit 1eec925

Please sign in to comment.