source: trip-planner-front/node_modules/svgo/plugins/removeEmptyText.js@ 188ee53

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.4 KB
Line 
1'use strict';
2
3const { detachNodeFromParent } = require('../lib/xast.js');
4
5exports.name = 'removeEmptyText';
6exports.type = 'visitor';
7exports.active = true;
8exports.description = 'removes empty <text> elements';
9
10/**
11 * Remove empty Text elements.
12 *
13 * @see https://www.w3.org/TR/SVG11/text.html
14 *
15 * @example
16 * Remove empty text element:
17 * <text/>
18 *
19 * Remove empty tspan element:
20 * <tspan/>
21 *
22 * Remove tref with empty xlink:href attribute:
23 * <tref xlink:href=""/>
24 *
25 * @author Kir Belevich
26 *
27 * @type {import('../lib/types').Plugin<{
28 * text?: boolean,
29 * tspan?: boolean,
30 * tref?: boolean
31 * }>}
32 */
33exports.fn = (root, params) => {
34 const { text = true, tspan = true, tref = true } = params;
35 return {
36 element: {
37 enter: (node, parentNode) => {
38 // Remove empty text element
39 if (text && node.name === 'text' && node.children.length === 0) {
40 detachNodeFromParent(node, parentNode);
41 }
42 // Remove empty tspan element
43 if (tspan && node.name === 'tspan' && node.children.length === 0) {
44 detachNodeFromParent(node, parentNode);
45 }
46 // Remove tref with empty xlink:href attribute
47 if (
48 tref &&
49 node.name === 'tref' &&
50 node.attributes['xlink:href'] == null
51 ) {
52 detachNodeFromParent(node, parentNode);
53 }
54 },
55 },
56 };
57};
Note: See TracBrowser for help on using the repository browser.