From a8a12999d640f11b3787d5f6488f667f78ada8e1 Mon Sep 17 00:00:00 2001 From: Cosmin Popovici Date: Sun, 9 Oct 2022 01:41:22 +0300 Subject: [PATCH] refactor: parsing attributes in sixHex transformer use vanilla js instead of posthtml-attrs-parser --- src/transformers/sixHex.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/transformers/sixHex.js b/src/transformers/sixHex.js index 74d638d1..966fb033 100644 --- a/src/transformers/sixHex.js +++ b/src/transformers/sixHex.js @@ -1,6 +1,5 @@ const {get} = require('lodash') const posthtml = require('posthtml') -const parseAttrs = require('posthtml-attrs-parser') const {conv} = require('color-shorthand-hex-to-six-digit') module.exports = async (html, config = {}) => { @@ -13,18 +12,16 @@ module.exports = async (html, config = {}) => { } const sixHex = () => tree => { - const process = node => { - const attrs = parseAttrs(node.attrs) - - const targets = ['bgcolor', 'color'] + const targets = new Set(['bgcolor', 'color']) - targets.forEach(attribute => { - if (attrs[attribute]) { - attrs[attribute] = conv(attrs[attribute]) - } - }) - - node.attrs = attrs.compose() + const process = node => { + if (node.attrs) { + Object.entries(node.attrs).forEach(([name, value]) => { + if (targets.has(name) && node.attrs[name]) { + node.attrs[name] = conv(value) + } + }) + } return node }