Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | const { detachNodeFromParent } = require('../lib/xast.js');
|
---|
4 |
|
---|
5 | exports.name = 'removeDesc';
|
---|
6 | exports.type = 'visitor';
|
---|
7 | exports.active = true;
|
---|
8 | exports.description = 'removes <desc>';
|
---|
9 |
|
---|
10 | const standardDescs = /^(Created with|Created using)/;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Removes <desc>.
|
---|
14 | * Removes only standard editors content or empty elements 'cause it can be used for accessibility.
|
---|
15 | * Enable parameter 'removeAny' to remove any description.
|
---|
16 | *
|
---|
17 | * https://developer.mozilla.org/en-US/docs/Web/SVG/Element/desc
|
---|
18 | *
|
---|
19 | * @author Daniel Wabyick
|
---|
20 | *
|
---|
21 | * @type {import('../lib/types').Plugin<{ removeAny?: boolean }>}
|
---|
22 | */
|
---|
23 | exports.fn = (root, params) => {
|
---|
24 | const { removeAny = true } = params;
|
---|
25 | return {
|
---|
26 | element: {
|
---|
27 | enter: (node, parentNode) => {
|
---|
28 | if (node.name === 'desc') {
|
---|
29 | if (
|
---|
30 | removeAny ||
|
---|
31 | node.children.length === 0 ||
|
---|
32 | (node.children[0].type === 'text' &&
|
---|
33 | standardDescs.test(node.children[0].value))
|
---|
34 | ) {
|
---|
35 | detachNodeFromParent(node, parentNode);
|
---|
36 | }
|
---|
37 | }
|
---|
38 | },
|
---|
39 | },
|
---|
40 | };
|
---|
41 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.