From 4c2cc1bbdba714df7a45ce3fe3de957d463a98bc Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sat, 11 Nov 2023 12:43:13 +0000 Subject: [PATCH] feat(inlineStyles): remove redundant presentation attrs (#1829) SVGs can have the same presentation attribute declared redundantly in both the node attributes and ` + + + `); + const stylesheet = collectStylesheet(root); + expect(computeStyle(stylesheet, getElementById(root, 'element'))).toEqual({ + animation: { + type: 'static', + inherited: false, + value: 'loading 4s linear infinite', + }, + }); +}); diff --git a/plugins/inlineStyles.js b/plugins/inlineStyles.js index 81245edba..db6bd2350 100644 --- a/plugins/inlineStyles.js +++ b/plugins/inlineStyles.js @@ -1,7 +1,6 @@ 'use strict'; /** - * @typedef {import('../lib/types').Specificity} Specificity * @typedef {import('../lib/types').XastElement} XastElement * @typedef {import('../lib/types').XastParent} XastParent */ @@ -16,7 +15,8 @@ const { querySelectorAll, detachNodeFromParent, } = require('../lib/xast.js'); -const { compareSpecificity } = require('../lib/style'); +const { compareSpecificity, includesAttrSelector } = require('../lib/style'); +const { attrsGroups } = require('./_collections'); exports.name = 'inlineStyles'; exports.description = 'inline styles (additional options)'; @@ -52,15 +52,12 @@ exports.fn = (root, params) => { return { element: { enter: (node, parentNode) => { - // skip content if (node.name === 'foreignObject') { return visitSkip; } - // collect only non-empty + + + +@@@ + + + + diff --git a/test/plugins/inlineStyles.25.svg b/test/plugins/inlineStyles.25.svg new file mode 100644 index 000000000..04e02878a --- /dev/null +++ b/test/plugins/inlineStyles.25.svg @@ -0,0 +1,32 @@ +Don't remove the redundant presentation attribute if it's used in a CSS +selector in a ` + + + + + + +@@@ + + + + + + + +