-
-
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.
Ref #1508 The new plugin removes xmlns:xlink from <svg> and replaces xlink:href with href attribute. xlink namespace is obsolete in SVG 2. Href attribute is recommended replacement to xlink:href. This plugin will be enabled by default in SVGO 3. See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/href
- Loading branch information
Showing
3 changed files
with
60 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,33 @@ | ||
'use strict'; | ||
|
||
exports.name = 'remove-xlink-ns'; | ||
exports.type = 'visitor'; | ||
exports.active = false; | ||
exports.description = | ||
'removes xmlns:xlink and replaces xlink:href with href attribute'; | ||
|
||
/** | ||
* removes xmlns:xlink from <svg> and replaces xlink:href with href attribute | ||
* | ||
* xlink namespace is obsolete in SVG 2. Href attribute is recommended | ||
* replacement to xlink:href. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/href | ||
* | ||
* @type {import('../lib/types').Plugin<void>} | ||
*/ | ||
exports.fn = () => { | ||
return { | ||
element: { | ||
enter: (node) => { | ||
if (node.attributes['xmlns:xlink'] != null) { | ||
delete node.attributes['xmlns:xlink']; | ||
} | ||
if (node.attributes['xlink:href'] != null) { | ||
node.attributes['href'] = node.attributes['xlink:href']; | ||
delete node.attributes['xlink:href']; | ||
} | ||
}, | ||
}, | ||
}; | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.