diff --git a/docs/03-plugins/remove-unknowns-and-defaults.mdx b/docs/03-plugins/remove-unknowns-and-defaults.mdx index 38234ac26..6fc9ace11 100644 --- a/docs/03-plugins/remove-unknowns-and-defaults.mdx +++ b/docs/03-plugins/remove-unknowns-and-defaults.mdx @@ -13,6 +13,9 @@ svgo: defaultAttrs: description: If to remove attributes that are assigned their default value anyway. default: true + defaultMarkupDeclarations: + description: If to remove XML declarations that are assigned their default value. XML declarations are the properties in the <?xml … ?> block at the top of the document. + default: true uselessOverrides: description: If to remove attributes that are being if the same value is being inherited by it's parent element anyway. default: true @@ -29,6 +32,8 @@ svgo: Removes unknown elements and attributes, as well as attributes that are set to their default value. +This can also remove defaults from the XML declaration if present in the document, namely [`standalone`](https://www.w3.org/TR/REC-xml/#sec-rmd) if it's set to `no`. + ## Usage diff --git a/docs/03-plugins/remove-xml-proc-inst.mdx b/docs/03-plugins/remove-xml-proc-inst.mdx index 05295d15e..12124a96d 100644 --- a/docs/03-plugins/remove-xml-proc-inst.mdx +++ b/docs/03-plugins/remove-xml-proc-inst.mdx @@ -17,7 +17,7 @@ An XML declaration is the line at the top of an XML file to indicate document me The XML declaration is optional in [XML 1.0](https://www.w3.org/TR/REC-xml/#sec-prolog-dtd), but mandatory in the [XML 1.1](https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-prolog-dtd). If the XML declaration is omitted, the document is assumed to follow the XML 1.0 specifications, which won't impact SVG documents. -It can be safely removed without impacting compatibility. +It can be safely removed without impacting compatibility with SVG clients. However, some tools may fail to detect the MIME-type as `image/svg+xml` if this is removed. ## Usage diff --git a/plugins/plugins-types.d.ts b/plugins/plugins-types.d.ts index 0499f627f..7cd56706a 100644 --- a/plugins/plugins-types.d.ts +++ b/plugins/plugins-types.d.ts @@ -14,8 +14,8 @@ type DefaultPlugins = { cleanupIds: { remove?: boolean; minify?: boolean; - preserve?: Array; - preservePrefixes?: Array; + preserve?: string[]; + preservePrefixes?: string[]; force?: boolean; }; cleanupNumericValues: { @@ -146,7 +146,7 @@ type DefaultPlugins = { }; removeDoctype: void; removeEditorsNSData: { - additionalNamespaces?: Array; + additionalNamespaces?: string[]; }; removeEmptyAttrs: void; removeEmptyContainers: void; @@ -179,6 +179,12 @@ type DefaultPlugins = { unknownContent?: boolean; unknownAttrs?: boolean; defaultAttrs?: boolean; + /** + * If to remove XML declarations that are assigned their default value. XML + * declarations are the properties in the `` block at the top of + * the document. + */ + defaultMarkupDeclarations?: boolean; uselessOverrides?: boolean; keepDataAttrs?: boolean; keepAriaAttrs?: boolean; @@ -194,7 +200,7 @@ type DefaultPlugins = { removeViewBox: void; removeXMLProcInst: void; sortAttrs: { - order?: Array; + order?: string[]; xmlnsOrder?: 'front' | 'alphabetical'; }; sortDefsChildren: void; @@ -262,17 +268,17 @@ export type BuiltinsWithRequiredParams = { }; addClassesToSVGElement: { className?: string; - classNames?: Array; + classNames?: string[]; }; removeAttributesBySelector: any; removeAttrs: { elemSeparator?: string; preserveCurrentColor?: boolean; - attrs: string | Array; + attrs: string | string[]; }; removeElementsByAttr: { - id?: string | Array; - class?: string | Array; + id?: string | string[]; + class?: string | string[]; }; }; diff --git a/plugins/removeUnknownsAndDefaults.js b/plugins/removeUnknownsAndDefaults.js index 410b36554..7462e8dc9 100644 --- a/plugins/removeUnknownsAndDefaults.js +++ b/plugins/removeUnknownsAndDefaults.js @@ -99,6 +99,7 @@ exports.fn = (root, params) => { unknownContent = true, unknownAttrs = true, defaultAttrs = true, + defaultMarkupDeclarations = true, uselessOverrides = true, keepDataAttrs = true, keepAriaAttrs = true, @@ -107,6 +108,13 @@ exports.fn = (root, params) => { const stylesheet = collectStylesheet(root); return { + instruction: { + enter: (node) => { + if (defaultMarkupDeclarations) { + node.value = node.value.replace(/\s*standalone\s*=\s*(["'])no\1/, ''); + } + }, + }, element: { enter: (node, parentNode) => { // skip namespaced elements diff --git a/test/plugins/removeUnknownsAndDefaults.16.svg b/test/plugins/removeUnknownsAndDefaults.16.svg new file mode 100644 index 000000000..6097eca2c --- /dev/null +++ b/test/plugins/removeUnknownsAndDefaults.16.svg @@ -0,0 +1,17 @@ +Removes standalone="no" XML declaration. + +See: https://github.com/svg/svgo/issues/836 + +=== + + + + uwu + + +@@@ + + + + uwu +