Skip to content

Commit

Permalink
Updated docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 committed Sep 19, 2024
1 parent d8c3ea8 commit 9102aab
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 36 deletions.
26 changes: 26 additions & 0 deletions docs/04-plugins/removeUnknownsAndDefaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# removeUnknownsAndDefaults

Removes unknown elements and attributes, as well as attributes that are set to their default value.
It also removes the the `standalone` declaration from the DTD if [`standalone`](https://www.w3.org/TR/REC-xml/#sec-rmd) is set to `no`.

The plugin has no effect if:

- The document has scripts.
- The document has `<style>` elements with CSS which **svgo-ll** is not able to process.

The following elements are not processed:

- Any element with a namespace prefix.
- Any `<foreignObject>` elements and their children.
- Any attributes whose name starts with `aria-` or `data-i`.
- `xmlns` attributes are never removed.
- Attribues with a namespace prefix are never removed unless the prefix is `xml` or `xlink`.

Elements are removed if:

- They are not allowed as children of their parents.

Attributes set to a default value are removed if:

- They are not overriding a value set by an ancestor, and
- they are not in an element which is referenced by a `<use>` element (or a child of any such element)
35 changes: 0 additions & 35 deletions docs/04-plugins/removeUnknownsAndDefaults.mdx

This file was deleted.

26 changes: 26 additions & 0 deletions docs/plugins/removeUnknownsAndDefaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# removeUnknownsAndDefaults

Removes unknown elements and attributes, as well as attributes that are set to their default value.
It also removes the the `standalone` declaration from the DTD if [`standalone`](https://www.w3.org/TR/REC-xml/#sec-rmd) is set to `no`.

The plugin has no effect if:

- The document has scripts.
- The document has `<style>` elements with CSS which **svgo-ll** is not able to process.

The following elements are not processed:

- Any element with a namespace prefix.
- Any `<foreignObject>` elements and their children.
- Any attributes whose name starts with `aria-` or `data-i`.
- `xmlns` attributes are never removed.
- Attribues with a namespace prefix are never removed unless the prefix is `xml` or `xlink`.

Elements are removed if:

- They are not allowed as children of their parents.

Attributes set to a default value are removed if:

- They are not overriding a value set by an ancestor, and
- they are not in an element which is referenced by a `<use>` element (or a child of any such element)
2 changes: 1 addition & 1 deletion docs/preset-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following plugins are included in `preset-default`, in the order that they'r
- cleanupIds
- removeUselessDefs
- convertColors
- removeUnknownsAndDefaults
- [removeUnknownsAndDefaults](./plugins/removeUnknownsAndDefaults.md)
- removeNonInheritableGroupAttrs
- removeUselessStrokeAndFill
- removeHiddenElems
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeUnknownsAndDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export const fn = (root, params, info) => {
parentNode.name,
);
if (allowedChildren == null || allowedChildren.size === 0) {
// TODO: DO WE NEED THIS CHECK? SHOULDN'T IT HAVE BEEN HANDLED BY THE PARENT IN THE ELSE BLOCK BELOW?
// remove unknown elements
if (allowedChildrenPerElement.get(node.name) == null) {
detachNodeFromParent(node, parentNode);
Expand Down Expand Up @@ -263,6 +264,7 @@ export const fn = (root, params, info) => {
saveForUsageCheck(node, name);
}
}
// TODO: DO WE NEED THE ID CHECK? SEEMS LIKE THIS IS HANDLED BY CHECKING FOR USE
if (uselessOverrides && node.attributes.id == null) {
const computedValue = computedParentStyle
? computedParentStyle.get(name)
Expand Down

0 comments on commit 9102aab

Please sign in to comment.