From 1eec925c1ba85101e61793454258fde2658f8399 Mon Sep 17 00:00:00 2001 From: Cosmin Popovici Date: Sun, 9 Oct 2022 02:06:43 +0300 Subject: [PATCH] refactor: remove inline sizes transformer --- src/transformers/removeInlineSizes.js | 7 ++++--- src/utils/helpers.js | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/transformers/removeInlineSizes.js b/src/transformers/removeInlineSizes.js index c2549ae6..98392d7b 100644 --- a/src/transformers/removeInlineSizes.js +++ b/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', {}) @@ -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 } diff --git a/src/utils/helpers.js b/src/utils/helpers.js index c9fb216c..bc6d26d1 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -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('; ') }