Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inlineStyles): dont remove id if traversed in another selector #1836

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading