Skip to content

Commit

Permalink
docs: fix typo in reuse-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Nov 26, 2023
1 parent 92a8f4d commit 56b1217
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/03-plugins/reuse-paths.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

:::

Expand Down
4 changes: 2 additions & 2 deletions lib/xast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions plugins/removeHiddenElems.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ exports.fn = (root, params) => {

/**
* IDs for removed hidden definitions.
*
*
* @type {Set<string>}
*/
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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 56b1217

Please sign in to comment.