mirror of
https://github.com/svg/svgo.git
synced 2026-01-27 07:02:06 +03:00
MDN used to redirect hits to `/docs` to the users locale, however they stopped doing that for some reason. This broke all MDN links on our documentation/JSDocs. This inserts `en-US` to all MDN URLs which fixes the links. (Unfortunately, this means all users may be taken to the English site regardless of their language preference.)
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import { detachNodeFromParent } from '../lib/xast.js';
|
|
|
|
/**
|
|
* @typedef RemoveDescParams
|
|
* @property {boolean=} removeAny
|
|
*/
|
|
|
|
export const name = 'removeDesc';
|
|
export const description = 'removes <desc>';
|
|
|
|
const standardDescs = /^(Created with|Created using)/;
|
|
|
|
/**
|
|
* Removes <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/en-US/docs/Web/SVG/Element/desc
|
|
*
|
|
* @type {import('../lib/types.js').Plugin<RemoveDescParams>}
|
|
*/
|
|
export const fn = (root, params) => {
|
|
const { removeAny = false } = params;
|
|
return {
|
|
element: {
|
|
enter: (node, parentNode) => {
|
|
if (node.name === 'desc') {
|
|
if (
|
|
removeAny ||
|
|
node.children.length === 0 ||
|
|
(node.children[0].type === 'text' &&
|
|
standardDescs.test(node.children[0].value))
|
|
) {
|
|
detachNodeFromParent(node, parentNode);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
};
|
|
};
|