From 56b121774089a38fcdd650cef83b5d992ea8a707 Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sun, 26 Nov 2023 15:07:54 +0000 Subject: [PATCH] docs: fix typo in reuse-paths --- docs/03-plugins/reuse-paths.mdx | 2 +- lib/xast.js | 4 ++-- plugins/removeHiddenElems.js | 25 +++++++++++++------------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/03-plugins/reuse-paths.mdx b/docs/03-plugins/reuse-paths.mdx index f787b8ad0..930d04853 100644 --- a/docs/03-plugins/reuse-paths.mdx +++ b/docs/03-plugins/reuse-paths.mdx @@ -12,7 +12,7 @@ If the path contains other attributes, such as `style` or `transform`, they will :::tip -If you only need SVG 2 or inline HTML compatibility, it's recommended to include the [Remove Xlink](/docs/plugins/remove-xlink/) plugin towards the end of your pipeline to convert references to `xlink:href` to the SVG 2 `href` attribute. +If you only need SVG 2 or inline HTML compatibility, it's recommended to include the [Remove XLink](/docs/plugins/remove-xlink/) plugin towards the end of your pipeline to convert references to `xlink:href` to the SVG 2 `href` attribute. ::: diff --git a/lib/xast.js b/lib/xast.js index 98ef5c17a..7f14e2a87 100644 --- a/lib/xast.js +++ b/lib/xast.js @@ -77,8 +77,8 @@ const visit = (node, visitor, parentNode) => { exports.visit = visit; /** - * @param {XastChild} node - * @param {XastParent} parentNode + * @param {XastChild} node + * @param {XastParent} parentNode */ const detachNodeFromParent = (node, parentNode) => { // avoid splice to not break for loops diff --git a/plugins/removeHiddenElems.js b/plugins/removeHiddenElems.js index c09117000..e708d5be5 100644 --- a/plugins/removeHiddenElems.js +++ b/plugins/removeHiddenElems.js @@ -69,20 +69,20 @@ exports.fn = (root, params) => { /** * IDs for removed hidden definitions. - * + * * @type {Set} */ const removedDefIds = new Set(); /** - * @param {XastChild} node - * @param {XastParent} parentNode + * @param {XastChild} node + * @param {XastParent} parentNode */ function removeElement(node, parentNode) { if ( node.type === 'element' && node.attributes.id != null && - parentNode.type === 'element' && + parentNode.type === 'element' && parentNode.name === 'defs' ) { removedDefIds.add(node.attributes.id); @@ -352,19 +352,18 @@ exports.fn = (root, params) => { }, exit: (node, parentNode) => { - if ( - node.name === 'defs' && - node.children.length === 0 - ) { + if (node.name === 'defs' && node.children.length === 0) { removeElement(node, parentNode); return; } - + if (node.name === 'use') { const referencesRemovedDef = Object.entries(node.attributes).some( ([attrKey, attrValue]) => (attrKey === 'href' || attrKey.endsWith(':href')) && - removedDefIds.has(attrValue.slice(attrValue.indexOf('#') + 1).trim()) + removedDefIds.has( + attrValue.slice(attrValue.indexOf('#') + 1).trim() + ) ); if (referencesRemovedDef) { @@ -378,9 +377,11 @@ exports.fn = (root, params) => { nonRenderedParent, ] of nonRenderedNodes.entries()) { const selector = referencesProps - .map((attr) => `[${attr}="url(#${nonRenderedNode.attributes.id})"]`) + .map( + (attr) => `[${attr}="url(#${nonRenderedNode.attributes.id})"]` + ) .join(','); - + const element = querySelector(root, selector); if (element == null) { detachNodeFromParent(node, nonRenderedParent);