Skip to content

Commit

Permalink
fix(inlineStyles): dont remove id if traversed in another selector (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco authored Nov 14, 2023
1 parent 0e5f0f1 commit 9809b67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ svgo one.svg two.svg -o one.min.svg two.min.svg
Process a directory of files recursively with `-f`/`--folder`:

```sh
svgo -f ./path/to/folder/with/svg/files -o ./path/to/folder/with/svg/output
svgo -f path/to/directory_with_svgs -o path/to/output_directory
```

Help for advanced usage:
Expand All @@ -48,7 +48,7 @@ svgo --help

SVGO has a plugin architecture. You can read more about all plugins in [Plugins | SVGO Documentation](https://svgo.dev/docs/plugins/), and the default plugins in [Preset Default | SVGO Documentation](https://svgo.dev/docs/preset-default/).

SVGO reads the configuration from `svgo.config.js` or the `--config {{path/to/config.js}}` command-line option. Some other parameters can be configured though command-line options too.
SVGO reads the configuration from `svgo.config.js` or the `--config path/to/config.js` command-line option. Some other parameters can be configured though command-line options too.

**`svgo.config.js`**
```js
Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = {
// disable a default plugin
removeViewBox: false,

// customize the options of a default plugin
// customize the params of a default plugin
inlineStyles: {
onlyMatchedOnce: false,
}
Expand Down
13 changes: 10 additions & 3 deletions plugins/inlineStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,16 @@ exports.fn = (root, params) => {
// ID
const firstSubSelector = selector.node.children.first;
if (
firstSubSelector != null &&
firstSubSelector.type === 'IdSelector' &&
selectedEl.attributes.id === firstSubSelector.name
firstSubSelector?.type === 'IdSelector' &&
selectedEl.attributes.id === firstSubSelector.name &&
!selectors.some((selector) =>
includesAttrSelector(
selector.item,
'id',
firstSubSelector.name,
true
)
)
) {
delete selectedEl.attributes.id;
}
Expand Down

0 comments on commit 9809b67

Please sign in to comment.