-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
removeDesc.js
37 lines (34 loc) · 1017 Bytes
/
removeDesc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { detachNodeFromParent } from '../lib/xast.js';
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/docs/Web/SVG/Element/desc
*
* @type {import('./plugins-types.js').Plugin<'removeDesc'>}
*/
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);
}
}
},
},
};
};