Skip to content

Commit

Permalink
chore: disable removeTitle from default plugins (svg#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed May 24, 2024
1 parent 3d2a624 commit c86536e
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 620 deletions.
601 changes: 0 additions & 601 deletions CHANGELOG-old.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default {
params: {
overrides: {
// disable a default plugin
removeViewBox: false,
cleanupIds: false,

// customize the params of a default plugin
inlineStyles: {
Expand Down
4 changes: 1 addition & 3 deletions docs/02-preset-default.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ The following plugins are included in `preset-default`, in the order that they'r
- [removeUnknownsAndDefaults](/docs/plugins/removeUnknownsAndDefaults/)
- [removeNonInheritableGroupAttrs](/docs/plugins/removeNonInheritableGroupAttrs/)
- [removeUselessStrokeAndFill](/docs/plugins/removeUselessStrokeAndFill/)
- [removeViewBox](/docs/plugins/removeViewBox/)
- [cleanupEnableBackground](/docs/plugins/cleanupEnableBackground/)
- [removeHiddenElems](/docs/plugins/removeHiddenElems/)
- [removeEmptyText](/docs/plugins/removeEmptyText/)
Expand All @@ -47,7 +46,6 @@ The following plugins are included in `preset-default`, in the order that they'r
- [mergePaths](/docs/plugins/mergePaths/)
- [sortAttrs](/docs/plugins/sortAttrs/)
- [sortDefsChildren](/docs/plugins/sortDefsChildren/)
- [removeTitle](/docs/plugins/removeTitle/)
- [removeDesc](/docs/plugins/removeDesc/)

## Disable a Plugin
Expand All @@ -63,7 +61,7 @@ module.exports = {
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
cleanupIds: false,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/03-plugins/removeDimensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Removes the [`width`](https://developer.mozilla.org/docs/Web/SVG/Attribute/width

:::info

This is effectively the opposite of the [removeViewBox](/docs/plugins/removeViewBox/) plugin, you should disable that before using this one.
This is effectively the opposite of the [removeViewBox](/docs/plugins/removeViewBox/) plugin, ensure that is disabled before using this one.

:::
1 change: 0 additions & 1 deletion docs/03-plugins/removeTitle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
title: removeTitle
svgo:
pluginId: removeTitle
defaultPlugin: true
---

Removes the [`<title>`](https://developer.mozilla.org/docs/Web/SVG/Element/title) element from the document.
Expand Down
2 changes: 0 additions & 2 deletions docs/03-plugins/removeViewBox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Removes the [`viewBox`](https://developer.mozilla.org/docs/Web/SVG/Attribute/vie

This plugin prevents SVGs from scaling, so they will not fill their parent container, or may clip if the container is too small.

Some external tools that use SVGO have also been found to override the default preset to disable this plugin by default, including [Docusaurus](https://github.com/facebook/docusaurus/blob/e17784effa2c370d81c7806c22ad19c6dce4a1cc/packages/docusaurus-utils/src/webpackUtils.ts#L127) and [SVGR](https://react-svgr.com/docs/migrate/#svgo).

See [svg/svgo#1128](https://github.com/svg/svgo/issues/1128) for more context.

:::
4 changes: 2 additions & 2 deletions plugins/plugins-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ type DefaultPlugins = {
};
removeMetadata: void;
removeNonInheritableGroupAttrs: void;
removeTitle: void;
removeUnknownsAndDefaults: {
unknownContent?: boolean;
unknownAttrs?: boolean;
Expand All @@ -203,7 +202,6 @@ type DefaultPlugins = {
fill?: boolean;
removeNone?: boolean;
};
removeViewBox: void;
removeXMLProcInst: void;
sortAttrs: {
order?: string[];
Expand Down Expand Up @@ -253,6 +251,8 @@ export type BuiltinsWithOptionalParams = DefaultPlugins & {
removeRasterImages: void;
removeScriptElement: void;
removeStyleElement: void;
removeTitle: void;
removeViewBox: void;
removeXlink: {
/**
* By default this plugin ignores legacy elements that were deprecated or
Expand Down
2 changes: 0 additions & 2 deletions plugins/preset-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import * as mergePaths from './mergePaths.js';
import * as removeUnusedNS from './removeUnusedNS.js';
import * as sortAttrs from './sortAttrs.js';
import * as sortDefsChildren from './sortDefsChildren.js';
import * as removeTitle from './removeTitle.js';
import * as removeDesc from './removeDesc.js';

const presetDefault = createPreset({
Expand Down Expand Up @@ -71,7 +70,6 @@ const presetDefault = createPreset({
removeUnusedNS,
sortAttrs,
sortDefsChildren,
removeTitle,
removeDesc,
],
});
Expand Down
8 changes: 4 additions & 4 deletions plugins/removeDesc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const standardDescs = /^(Created with|Created using)/;

/**
* Removes <desc>.
* Removes only standard editors content or empty elements 'cause it can be used for accessibility.
* Enable parameter 'removeAny' to remove any description.
*
* https://developer.mozilla.org/docs/Web/SVG/Element/desc
* Removes only standard editors content or empty elements because it can be
* used for accessibility. Enable parameter 'removeAny' to remove any
* description.
*
* @author Daniel Wabyick
* @see https://developer.mozilla.org/docs/Web/SVG/Element/desc
*
* @type {import('./plugins-types.js').Plugin<'removeDesc'>}
*/
Expand Down
4 changes: 2 additions & 2 deletions test/cli/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ test('accepts svg as input stream', async () => {
const proc = spawn('node', ['../../bin/svgo', '--no-color', '-'], {
cwd: __dirname,
});
proc.stdin.write('<svg><title>stdin</title></svg>');
proc.stdin.write('<svg><desc>Created with Love</desc></svg>');
proc.stdin.end();
const stdout = await waitStdout(proc);
expect(stdout).toBe('<svg/>');
});

test('accepts svg as string', async () => {
const input = '<svg><title>string</title></svg>';
const input = '<svg><desc>Created with Love</desc></svg>';
const proc = spawn(
'node',
['../../bin/svgo', '--no-color', '--string', input],
Expand Down
2 changes: 1 addition & 1 deletion test/cli/single.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c86536e

Please sign in to comment.