-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(removeDeprecatedAttrs): new removeDeprecatedAttrs plugin
The new removeDeprecatedAttributes removes deprecated attributes from the SVG document that have no effect on rendering. For example, the "version" attribute on the "svg" element is deprecated and not recommended as documented on MDN: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/version > Deprecated: This feature is no longer recommended. Though some > browsers might still support it, it may have already been removed from > the relevant web standards, may be in the process of being dropped, or > may only be kept for compatibility purposes. Avoid using it, and > update existing code if possible; see the compatibility table at the > bottom of this page to guide your decision. Be aware that this feature > may cease to work at any time. The document: ``` <svg version="1.1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <rect x="10" y="10" width="80" height="80"/> </svg> ``` Becomes: ``` <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <rect x="10" y="10" width="80" height="80"/> </svg> ``` The plugin is built for easy expansion as new deprecated attributes are discovered or announced. Simply add a "deprecated" key to the elems data structure in plugins/_collections.js. Fixes #1701
- Loading branch information
Showing
8 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: Remove Deprecated Attributes | ||
svgo: | ||
pluginId: removeDeprecatedAttrs | ||
defaultPlugin: true | ||
--- | ||
|
||
Remove deprecated attributes from elements in the document. | ||
|
||
## Usage | ||
|
||
<PluginUsage/> | ||
|
||
## Demo | ||
|
||
<PluginDemo/> | ||
|
||
## Implementation | ||
|
||
* https://github.com/svg/svgo/blob/main/plugins/removeDeprecatedAttrs.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const { elems } = require('./_collections'); | ||
|
||
exports.name = 'removeDeprecatedAttrs'; | ||
exports.description = 'removes deprecated attributes'; | ||
|
||
/** | ||
* Remove deprecated attributes. | ||
* | ||
* @type {import('./plugins-types').Plugin<'removeDeprecatedAttrs'>} | ||
*/ | ||
exports.fn = () => { | ||
return { | ||
element: { | ||
enter: (node) => { | ||
const elemConfig = elems[node.name]; | ||
if (elemConfig) { | ||
const deprecated = elemConfig.deprecated; | ||
if (deprecated) { | ||
deprecated.forEach((name) => { | ||
delete node.attributes[name]; | ||
}); | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.